Codeforces Round 446 (Div. 1)
C
Envy
Codeforces
2300
原题
← BD →
翻译中…

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.

翻译中…

Input

翻译中…

The first line contains two integers $*n*$, $*m*$ ($2  ≤ *n*, *m*  ≤ 5·10^{5}$, $*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·10^{5}$) — 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·10^{5}$) — 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·10^{5}$.

翻译中…

Output

翻译中…

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.

翻译中…

Note

翻译中…

This is the graph of sample:

翻译中…

image

翻译中…

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".

翻译中…

样例

Input #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
Output #1
YES
NO
YES
NO
InputCopy OutputCopy
题目信息
题号
891C
时间限制
2 s
内存限制
256 MB
标签
数据结构
并查集
图论

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。