A14486 | Building Forest Trails
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
There are $n$ villages lying equidistant on a circle in the middle of a thick, impassable forest. From ancient times, it was impossible to move from one village to another, but technical progress has changed a lot. Now, there is a technology to build passable trails in the forest.
The building process consists of $m$ events. Each event is either building a trail or querying if two villages are connected. Trails are built as straight lines connecting two villages. After a trail is built, anybody can walk along the trail from one village to another.
Moreover, if two trails cross, anybody can turn at the intersection, and if other trails leave a village you have just reached, they can also be used to walk along. So, for example, if villages are numbered $1$ to $6$ in the order around the circle, and there are trails $1$ to $3$ , $2$ to $4$ , and $4$ to $6$ , then all villages, except the $5$ -th, are reachable from the $1$ -st village.
Given a list of $m$ events, for each query, find if two given villages are reachable from each other at that moment.
The building process consists of $m$ events. Each event is either building a trail or querying if two villages are connected. Trails are built as straight lines connecting two villages. After a trail is built, anybody can walk along the trail from one village to another.
Moreover, if two trails cross, anybody can turn at the intersection, and if other trails leave a village you have just reached, they can also be used to walk along. So, for example, if villages are numbered $1$ to $6$ in the order around the circle, and there are trails $1$ to $3$ , $2$ to $4$ , and $4$ to $6$ , then all villages, except the $5$ -th, are reachable from the $1$ -st village.
Given a list of $m$ events, for each query, find if two given villages are reachable from each other at that moment.
输入格式
The first line contains two integers $n$ ( $2 \le n \le 2\cdot 10^5$ ) and $m$ ( $1 \le m \le 3\cdot 10^5$ ) — the number of villages and the number of events respectively.
Next $m$ lines contain events. Each event description consists of three integers $e$ ( $e$ is $1$ or $2$ ), $v$ ( $1 \le v \le n$ ), and $u$ ( $1 \le u \le n$ , $u \ne v$ ). If $e = 1$ , then the event is building a trail between villages $v$ and $u$ . If $e = 2$ , then the event is a query if the villages $v$ and $u$ are connected. It is guaranteed that each trail is built at most once.
Villages are numbered $1$ to $n$ in clockwise order around the circle.
Next $m$ lines contain events. Each event description consists of three integers $e$ ( $e$ is $1$ or $2$ ), $v$ ( $1 \le v \le n$ ), and $u$ ( $1 \le u \le n$ , $u \ne v$ ). If $e = 1$ , then the event is building a trail between villages $v$ and $u$ . If $e = 2$ , then the event is a query if the villages $v$ and $u$ are connected. It is guaranteed that each trail is built at most once.
Villages are numbered $1$ to $n$ in clockwise order around the circle.
输出格式
For each query print one character '0' if villages are not reachable, and '1' if villages are reachable from each other. Print answers for all queries as a single string in one line.
输入输出样例
输入 #1
6 9 1 1 3 1 4 6 2 3 4 1 2 4 2 1 2 2 1 3 2 1 4 2 6 1 2 5 3
输出 #1
011110
输入 #2
2 5 2 1 2 2 2 1 1 1 2 2 1 2 2 2 1
输出 #2
0011
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted