CF891C Envy
Description
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 Format
The first line contains two integers $ n $ , $ m $ ( $ 2
Output Format
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.
Explanation/Hint
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".