#P2173. [ZJOI2012] 网络

    ID: 1111 远端评测题 2000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2012各省省选平衡树浙江Link-Cut Tree,LCT

[ZJOI2012] 网络

Description

There is an undirected graph GG. Each node has a weight, and each edge has a color. This undirected graph satisfies the following two conditions:

  1. For any node, among all edges incident to it, there are at most two edges of the same color.

  2. There is no monochromatic cycle in the graph, i.e., no cycle formed by edges of the same color.

On this graph, you need to support the following three operations:

  • 0 x y means set the weight of node xx to yy.

  • 1 u v w means change the color of edge (u,v)(u, v) to ww.

  • 2 c u v means query, in the subgraph formed by edges of color cc, the maximum weight among all nodes that lie on any simple path from uu to vv.

Input Format

The first line contains four positive integers n,m,C,kn, m, C, k, denoting the number of nodes, the number of edges, the number of colors, and the number of operations, respectively.

The next nn lines each contain one positive integer viv_i, the weight of node ii.

The next mm lines each contain three positive integers u,v,wu, v, w, denoting an edge connecting nodes uu and vv with color ww.

The last kk lines each contain several positive integers, representing one operation.

Output Format

Output several lines, each containing the corresponding message.

  1. For node weight modification operations, no output is required.

  2. For edge color modification operations, print one of the following:

  • If there is no edge connecting node uu and node vv, print No such edge..

  • If the modification would violate condition 1, do not modify the edge color and print Error 1..

  • If the modification would violate condition 2, do not modify the edge color and print Error 2..

  • Otherwise, modify the edge color successfully and print Success..

Only print the first applicable message. That is, if both conditions 1 and 2 would be violated, print only Error 1..

  1. For query operations, print one integer as the answer. If there is no path of color cc between uu and vv, print 1-1.
4 5 2 7
1
2
3
4
1 2 0
1 3 1
2 3 0
2 4 1
3 4 0
2 0 1 4
1 1 2 1
1 4 3 1
2 0 1 4
1 2 3 1
0 2 5
2 1 1 4
4
Success.
Error 2.
-1
Error 1.
5

Hint

Edges of color 00 are solid; edges of color 11 are dashed.

In the subgraph formed by edges of color 00, there is a path from node 11 to node 44: 1241 \to 2 \to 4. Thus max{v1,v2,v4}=max{1,2,4}=4\max\{ v_1, v_2, v_4 \} = \max\{ 1, 2, 4 \} = 4.

Changing the edge between nodes 11 and 22 to color 11 succeeds, so print Success..

Changing the edge between nodes 44 and 33 to color 11 would create a monochromatic cycle of color 11 (124311 – 2 – 4 – 3 – 1), violating condition 2, so do not modify it and print Error 2..

There is no path of color 00 from node 11 to node 44, so print 1-1.

Changing the edge between nodes 22 and 33 to color 11 would make node 22 incident to three edges of color 11, violating condition 1, so do not modify it and print Error 1..

Change the weight of node 22 to 55.

In the subgraph formed by edges of color 11, there is a path from node 11 to node 44: 1241 \to 2 \to 4. Thus max{v1,v2,v4}=max{1,5,4}=5\max\{ v_1, v_2, v_4 \} = \max\{ 1, 5, 4 \} = 5.

Constraints

  • For 30%30\% of the testdata: n1000n \le 1000, m104m \le 10^4, k1000k \le 1000.
  • Additionally, for 20%20\% of the testdata: n104n \le 10^4, m105m \le 10^5, C=1C = 1, k105k \le 10^5.
  • For 100%100\% of the testdata: n104n \le 10^4, m105m \le 10^5, C10C \le 10, k105k \le 10^5.

1u,v,xn1 \le u, v, x \le n, 0c<C0 \le c < C. There are no multiple edges or self-loops in the graph.

Translated by ChatGPT 5