CF891C.Envy

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

For a connected undirected weighted graph GG , MST (minimum spanning tree) is a subgraph of GG that contains all of GG 's vertices, is a tree, and sum of its edges is minimum possible.

You are given a graph GG . 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 GG , and you should determine whether there is a MST containing all these edges or not.

输入格式

The first line contains two integers nn , mm ( 2<=n,m<=51052<=n,m<=5·10^{5} , n1<=mn-1<=m ) — the number of vertices and edges in the graph and the number of queries.

The ii -th of the next mm lines contains three integers uiu_{i} , viv_{i} , wiw_{i} ( uiviu_{i}≠v_{i} , 1<=wi<=51051<=w_{i}<=5·10^{5} ) — the endpoints and weight of the ii -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 qq ( 1<=q<=51051<=q<=5·10^{5} ) — the number of queries.

qq lines follow, the ii -th of them contains the ii -th query. It starts with an integer kik_{i} ( 1<=ki<=n11<=k_{i}<=n-1 ) — the size of edges subset and continues with kik_{i} distinct space-separated integers from 11 to mm — the indices of the edges. It is guaranteed that the sum of kik_{i} for 1<=i<=q1<=i<=q does not exceed 51055·10^{5} .

输出格式

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.

输入输出样例

  • 输入#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 66 .

MST with edges (1,3,4,6)(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 33 , so there is no spanning tree including these three edges. Thus, answer is "NO".

首页