CF1555F.Good Graph
省选/NOI-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You have an undirected graph consisting of n vertices with weighted edges.
A simple cycle is a cycle of the graph without repeated vertices. Let the weight of the cycle be the XOR of weights of edges it consists of.
Let's say the graph is good if all its simple cycles have weight 1. A graph is bad if it's not good.
Initially, the graph is empty. Then q queries follow. Each query has the next type:
- u v x — add edge between vertices u and v of weight x if it doesn't make the graph bad.
For each query print, was the edge added or not.
你有一个包含 n 个顶点的无向图,其边具有权重。
简单环是指图中不包含重复顶点的环。定义该环的权重为组成该环的所有边的权重的 XOR 值。
若图中所有简单环的权重均为 1,则称该图为好图;若图不是好图,则称其为坏图。
初始时,图为空。随后有 q 个查询,每个查询的格式如下:
- u v x — 若添加一条连接顶点 u 和 v、权重为 x 的边不会使图变为坏图,则执行添加操作。
对每个查询,请输出该边是否被成功添加。
输入格式
The first line contains two integers n and q (3≤n≤3⋅105; 1≤q≤5⋅105) — the number of vertices and queries.
Next q lines contain queries — one per line. Each query contains three integers u, v and x (1≤u,v≤n; u=v; 0≤x≤1) — the vertices of the edge and its weight.
It's guaranteed that there are no multiple edges in the input.
第一行包含两个整数 n 和 q(3≤n≤3⋅105;1≤q≤5⋅105)—— 分别表示顶点数和查询数。
接下来的 q 行每行包含一个查询。每个查询包含三个整数 u、v 和 x(1≤u,v≤n;u=v;0≤x≤1)—— 分别表示边的两个顶点及其权重。
保证输入中不存在重边。
输出格式
For each query, print YES if the edge was added to the graph, or NO otherwise (both case-insensitive).
对于每个查询,如果该边被添加到图中,则输出 YES;否则输出 NO(不区分大小写)。
输入输出样例
输入#1
9 12 6 1 0 1 3 1 3 6 0 6 2 0 6 4 1 3 4 1 2 4 0 2 5 0 4 5 0 7 8 1 8 9 1 9 7 0
输出#1
YES YES YES YES YES NO YES YES NO YES YES NO
输入解题思路,AI测评打分。不知道怎么写?