#abc235e. E - MST + 1

E - MST + 1

Score : 500500 points

问题描述

给定一个带权重的无向连通图 GG,包含 NN 个顶点和 MM 条边,该图可能包含自环和平行边。 顶点被标记为顶点 11、顶点 22\dots、顶点 NN。 边被标记为边 11、边 22\ldots、边 MM。边 ii 连接顶点 aia_i 和顶点 bib_i,其权重为 cic_i。这里对于任意一对整数 (i,j)(i, j) 满足 1i<jM1 \leq i < j \leq M,有 cicjc_i \neq c_j

处理以下 QQ 个查询: 第 ii 个查询给出一个三元组 (ui,vi,wi)(u_i, v_i, w_i)。这里对于任意整数 jj 满足 1jM1 \leq j \leq M,有 wicjw_i \neq c_j。 令 eie_i 表示连接顶点 uiu_i 和顶点 viv_i、权重为 wiw_i 的无向边。考虑通过在 GG 中添加 eie_i 得到的图 GiG_i。可以证明 GiG_i 的最小生成树 TiT_i 是唯一确定的。问 TiT_i 是否包含边 eie_i?打印答案 YesNo

注意:查询不会改变原始的 TT。换句话说,尽管第 ii 个查询考虑了通过在 GG 中添加 eie_i 得到的图,但在其他查询中的 GG 不包含 eie_i

什么是最小生成树? 生成树GG 中包含所有顶点及部分边构成的一棵树。 最小生成树GG 的生成树中具有最小总边权重的那棵树。

以上为通义千问 qwen-max 翻译,仅供参考。

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.

Sample Input 1

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

Sample Output 1

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.

Sample Input 2

2 3 2
1 2 100
1 2 1000000000
1 1 1
1 2 2
1 1 5

Sample Output 2

Yes
No

update @ 2024/3/10 10:12:23

}