CF891C.Envy
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
For a connected undirected weighted graph G, MST (minimum spanning tree) is a subgraph of G that contains all of G's vertices, is a tree, and sum of its edges is minimum possible.
You are given a graph G. If you run a MST algorithm on graph it would give you only one MST and it causes other edges to become jealous. You are given some queries, each query contains a set of edges of graph G, and you should determine whether there is a MST containing all these edges or not.
对于一个连通的无向带权图 G,其最小生成树(MST)是 G 的一个子图,该子图包含 G 的所有顶点、构成一棵树,且其所有边的权值之和为可能的最小值。
你被给定一个图 G。若在该图上运行 MST 算法,将仅得到唯一的一棵 MST,从而导致其余边“心生嫉妒”。你将收到若干查询,每个查询包含图 G 中的一组边;你需要判断是否存在一棵 MST 包含该查询中的所有边。
输入格式
The first line contains two integers n, m (2 ≤ n, m ≤ 5·105, n - 1 ≤ m) — the number of vertices and edges in the graph and the number of queries.
The i-th of the next m lines contains three integers u__i, v__i, w__i (u__i ≠ v__i, 1 ≤ w__i ≤ 5·105) — the endpoints and weight of the i-th edge. There can be more than one edges between two vertices. It's guaranteed that the given graph is connected.
The next line contains a single integer q (1 ≤ q ≤ 5·105) — the number of queries.
q lines follow, the i-th of them contains the i-th query. It starts with an integer k__i (1 ≤ k__i ≤ n - 1) — the size of edges subset and continues with k__i distinct space-separated integers from 1 to m — the indices of the edges. It is guaranteed that the sum of k__i for 1 ≤ i ≤ q does not exceed 5·105.
第一行包含两个整数 n、m(2≤n,m≤5⋅105,n−1≤m)—— 分别表示图中顶点数、边数以及查询次数。
接下来的 m 行中,第 i 行包含三个整数 ui、vi、wi(ui=vi,1≤wi≤5⋅105)—— 表示第 i 条边的两个端点及其权重。两个顶点之间可能存在多条边。保证所给图是连通的。
下一行包含一个整数 q(1≤q≤5⋅105)—— 表示查询次数。
随后是 q 行,第 i 行描述第 i 个查询:首先是一个整数 ki(1≤ki≤n−1)—— 表示边子集的大小,接着是 ki 个互不相同且以空格分隔的整数(取值范围为 1 到 m)—— 表示所选边的索引。保证对所有 1≤i≤q,所有 ki 的总和不超过 5⋅105。
输出格式
For each query you should print "YES" (without quotes) if there's a MST containing these edges and "NO" (of course without quotes again) otherwise.
对于每个查询,如果存在一棵包含这些边的最小生成树(MST),则输出 "YES"(不带引号);否则输出 "NO"(同样不带引号)。
输入输出样例
输入#1
5 7 1 2 2 1 3 2 2 3 1 2 4 1 3 4 1 3 5 2 4 5 2 4 2 3 4 3 3 4 5 2 1 7 2 1 2
输出#1
YES NO YES NO
说明/提示
This is the graph of sample:

Weight of minimum spanning tree on this graph is 6.
MST with edges (1, 3, 4, 6), contains all of edges from the first query, so answer on the first query is "YES".
Edges from the second query form a cycle of length 3, so there is no spanning tree including these three edges. Thus, answer is "NO".
这是样例的图:

该图的最小生成树(MST)的权值为 6。
由边 (1, 3, 4, 6) 构成的 MST 包含了第一个查询中的所有边,因此第一个查询的答案是 “YES”。
第二个查询中的边构成一个长度为 3 的环,因此不存在包含这三条边的生成树。故答案为 “NO”。
输入解题思路,AI测评打分。不知道怎么写?