atcoder#ABC235E. [ABC235E] MST + 1

[ABC235E] MST + 1

Score : 500500 points

Problem Statement

Given is a weighted undirected connected graph GG with NN vertices and MM edges, which may contain self-loops and multi-edges. The vertices are labeled as Vertex 11, Vertex 22, \dots, Vertex NN. The edges are labeled as Edge 11, Edge 22, \ldots, Edge MM. Edge ii connects Vertex aia_i and Vertex bib_i and has a weight of cic_i. Here, for every pair of integers (i,j)(i, j) such that 1i<jM1 \leq i \lt j \leq M, cicjc_i \neq c_j holds.

Process the QQ queries explained below. The ii-th query gives a triple of integers (ui,vi,wi)(u_i, v_i, w_i). Here, for every integer jj such that 1jM1 \leq j \leq M, wicjw_i \neq c_j holds. Let eie_i be an undirected edge that connects Vertex uiu_i and Vertex viv_i and has a weight of wiw_i. Consider the graph GiG_i obtained by adding eie_i to GG. It can be proved that the minimum spanning tree TiT_i of GiG_i is uniquely determined. Does TiT_i contain eie_i? Print the answer as Yes or No.

Note that the queries do not change TT. In other words, even though Query ii considers the graph obtained by adding eie_i to GG, the GG in other queries does not have eie_i.

What is minimum spanning tree?

The spanning tree of GG is a tree with all of the vertices in GG and some of the edges in GG. The minimum spanning tree of GG is the tree with the minimum total weight of edges among the spanning trees of GG.

Constraints

  • 2N2×1052 \leq N \leq 2 \times 10^5
  • N1M2×105N - 1 \leq M \leq 2 \times 10^5
  • 1aiN1 \leq a_i \leq N (1iM)(1 \leq i \leq M)
  • 1biN1 \leq b_i \leq N (1iM)(1 \leq i \leq M)
  • 1ci1091 \leq c_i \leq 10^9 (1iM)(1 \leq i \leq M)
  • cicjc_i \neq c_j (1i<jM)(1 \leq i \lt j \leq M)
  • The graph GG is connected.
  • 1Q2×1051 \leq Q \leq 2 \times 10^5
  • 1uiN1 \leq u_i \leq N (1iQ)(1 \leq i \leq Q)
  • 1viN1 \leq v_i \leq N (1iQ)(1 \leq i \leq Q)
  • 1wi1091 \leq w_i \leq 10^9 (1iQ)(1 \leq i \leq Q)
  • wicjw_i \neq c_j (1iQ,1jM)(1 \leq i \leq Q, 1 \leq j \leq M)
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN MM QQ

a1a_1 b1b_1 c1c_1

a2a_2 b2b_2 c2c_2

\vdots

aMa_M bMb_M cMc_M

u1u_1 v1v_1 w1w_1

u2u_2 v2v_2 w2w_2

\vdots

uQu_Q vQv_Q wQw_Q

Output

Print QQ lines. The ii-th line should contain the answer to Query ii: Yes or No.

5 6 3
1 2 2
2 3 3
1 3 6
2 4 5
4 5 9
3 5 8
1 3 1
3 4 7
3 5 7
Yes
No
Yes

Below, let (u,v,w)(u,v,w) denote an undirected edge that connects Vertex uu and Vertex vv and has the weight of ww. Here is an illustration of GG:

image

For example, Query 11 considers the graph G1G_1 obtained by adding e1=(1,3,1)e_1 = (1,3,1) to GG. The minimum spanning tree T1T_1 of G1G_1 has the edge set {(1,2,2),(1,3,1),(2,4,5),(3,5,8)}\lbrace (1,2,2),(1,3,1),(2,4,5),(3,5,8) \rbrace, which contains e1e_1, so Yes should be printed.

2 3 2
1 2 100
1 2 1000000000
1 1 1
1 2 2
1 1 5
Yes
No