#P2610. [ZJOI2012] 旅游

    ID: 1340 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>动态规划,dp2012各省省选浙江广度优先搜索,BFS树的直径

[ZJOI2012] 旅游

Description

During the rare summer vacation, to celebrate Xiaobai’s excellent performance in the math exam, Xiaolan decides to take Xiaobai on a trip~~

After some deliberation, they choose Country T as their destination. The territory of Country T can be represented by a convex nn-gon, and the nn vertices represent nn entry/exit ports. Country T contains n2n - 2 cities, each city being a triangle whose vertices are vertices of the nn-gon (in other words, the cities form a triangulation of Country T). The travel route of the two can be regarded as a line segment connecting two non-adjacent vertices among the nn vertices.

To buy the best souvenirs, Xiaobai hopes the route passes through as many cities as possible. As Xiaolan’s friend, can you help?

Input Format

Each input file contains only one test case.

The first line contains a positive integer nn, as described above.

Then there are n2n - 2 lines. Each line contains three integers p,q,rp, q, r, indicating the vertex indices of that city’s triangle (the nn vertices of Country T are numbered from 11 to nn in clockwise order).

Output Format

Output a single line: the maximum number of cities that can be passed through. (A city is counted as passed if and only if it shares at least two common points with the route.)

6
1 2 4
2 3 4
1 4 5
1 5 6
4

Hint

For 20%20\% of the testdata, n2000n \le 2000.

For 100%100\% of the testdata, 4n2000004 \le n \le 200000.

Translated by ChatGPT 5