#P4220. [WC2018] 通道

    ID: 3151 远端评测题 4000ms 500MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>搜索2018并查集点分治WC/CTSC/集训队分治虚树

[WC2018] 通道

Description

In the year 11328, scientists in country C developed a high-speed teleportation channel that can send residents from one end to the other in a very short time. These channels are bidirectional.

The downside is that such channels require extensive maintenance and inspection. After planning, the president of country C decided to build such channels in City M. In City M, nn teleportation stations and 3×(n1)3 \times (n-1) channels were built. These channels are divided into 33 groups, each containing (n1)(n-1) channels.

When any one group of channels is operating, residents can travel via this group of channels from any station to any other station. In other words, all stations are connected by channels.

The three groups of channels operate in a round-robin fashion in the order 11, 22, 33, repeatedly. At any moment, exactly one group of channels is available. Formally, on day ii, only group ((i1)mod3+1)((i-1)\bmod 3+1) is operating.

The renowned scientist Access Globe is conducting a social survey experiment: collecting information on users of the channels between two stations. Access Globe’s plan is as follows:

  • Choose two stations a,ba, b.
  • On day one, he starts from aa, uses the currently operating group of channels to reach bb along a shortest path, and surveys the users on all channels he traverses.
  • On day two, he starts from bb, uses the currently operating group of channels to reach aa along a shortest path, and surveys the users on all channels he traverses.
  • On day three, he starts from aa, uses the currently operating group of channels to reach bb along a shortest path, and surveys the users on all channels he traverses.

Access Globe knows the number of users on each channel when it is operating. He wants to find a pair a,ba, b such that the total number of users over all traversed channels during the entire experiment is maximized.

Access Globe hopes you, a participant of the CCF NOI 2018 Winter Camp, can help him solve this simple problem. If you succeed, Access Globe will give you a small gift — 100100 points.

Input Format

The first line contains a positive integer nn, the number of stations, numbered from 11 to nn.

Lines 22 to nn: each line contains three numbers u,v,wu, v, w, indicating that in the first group there is a channel connecting uu and vv, with ww users when it is operating.

Lines (n+1)(n+1) to (2n1)(2n-1): each line contains three numbers u,v,wu, v, w, indicating that in the second group there is a channel connecting uu and vv, with ww users when it is operating.

Lines 2n2n to (3n2)(3n-2): each line contains three numbers u,v,wu, v, w, indicating that in the third group there is a channel connecting uu and vv, with ww users when it is operating.

Output Format

Output a single line containing an integer: the maximum possible sum of user counts.

5
1 2 2
1 3 0
1 4 1
4 5 7
1 2 0
2 3 1
2 4 1
2 5 3
1 5 2
2 3 8
3 4 5
4 5 1
27

Hint

[Sample 1 Explanation]

The figure below shows the stations and channels in City MM for the sample. The alternating dotted-and-dashed lines, dotted lines, and solid lines denote the first, second, and third groups of channels, respectively. One feasible plan is to choose a=2,b=5a=2, b=5. The total number of users is (3)+(8+5+1)+(2+1+7)=27(3) + (8+5+1) + (2+1+7) = 27.

[Subtasks]

Constraints:

  • For all testdata, 2n1052 \le n \le 10^5, 0w10120 \le w \le 10^{12}.

Special properties:

  • Special property 00: Any two groups of channels are structurally identical.
  • Special property 11: The second and third groups of channels are structurally identical.
  • Special property 22: In the second group, each station has degree at most 22, and stations numbered x,yx, y are directly connected by a channel if and only if xy=1|x-y|=1.
  • Special property 33: In the third group, each station has degree at most 22.
  • Special property 44: n3000n \le 3000.

There are 3131 test points in total, with the following mapping from subtasks to test points:

  • Subtask 00: test points 1177.
  • Subtask 11: test point 88.
  • Subtask 22: test points 991111.
  • Subtask 33: test points 12121414.
  • Subtask 44: test points 15151717.
  • Subtask 55: test points 18182121.
  • Subtask 66: test points 22222525.
  • Subtask 77: test points 26263131.

[Notes]

  • It is possible that two groups both contain a channel connecting stations xx and yy. In that case, we consider these as two distinct channels.
  • In the special properties, “structurally identical” between groups A and B means: if there is a channel between uu and vv with user count ww in group A, then there must also be a channel between uu and vv with user count ww in group B. Whether they are considered identical is independent of the description format and the input order. That is, in two structurally identical groups A and B, the order of channel inputs may differ, and the order of endpoints in each channel’s input may also differ (for a channel connecting u,vu, v with user count ww in groups A and B, one possible input is u v wu\ v\ w for group A and v u wv\ u\ w for group B).

Translated by ChatGPT 5