A14386 | Good Graph
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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](https://en.wikipedia.org/wiki/Bitwise_operation#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.
A simple cycle is a cycle of the graph without repeated vertices. Let the weight of the cycle be the [XOR](https://en.wikipedia.org/wiki/Bitwise_operation#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.
输入格式
The first line contains two integers $n$ and $q$ ( $3 \le n \le 3 \cdot 10^5$ ; $1 \le q \le 5 \cdot 10^5$ ) — the number of vertices and queries.
Next $q$ lines contain queries — one per line. Each query contains three integers $u$ , $v$ and $x$ ( $1 \le u, v \le n$ ; $u \neq v$ ; $0 \le x \le 1$ ) — the vertices of the edge and its weight.
It's guaranteed that there are no multiple edges in the input.
Next $q$ lines contain queries — one per line. Each query contains three integers $u$ , $v$ and $x$ ( $1 \le u, v \le n$ ; $u \neq v$ ; $0 \le x \le 1$ ) — the vertices of the edge and its weight.
It's guaranteed that there are no multiple edges in the input.
输出格式
For each query, print YES if the edge was added to the graph, or NO otherwise (both case-insensitive).
输入输出样例
输入 #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
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted