CF1578B.Building Forest Trails

省选/NOI-

通过率:0%

时间限制:3.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

There are nn 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 mm 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 11 to 66 in the order around the circle, and there are trails 11 to 33, 22 to 44, and 44 to 66, then all villages, except the 55-th, are reachable from the 11-st village.

Given a list of mm events, for each query, find if two given villages are reachable from each other at that moment.

有 nn 个村庄均匀分布在一片浓密且不可穿越的森林中央的一个圆周上。自古以来,人们无法在村庄之间通行,但技术进步已带来巨大改变。如今,已有技术可在森林中修建可通行的小径。

修建过程包含 mm 个事件。每个事件要么是修建一条小径,要么是查询两个村庄在当前时刻是否连通。小径以连接两个村庄的直线段形式修建。一旦某条小径建成,任何人都可沿该小径从一个村庄步行至另一个村庄。

此外,若两条小径相交,则任何人可在交点处转向;若某人刚抵达一个村庄,而该村庄还有其他小径延伸出去,则这些小径也可用于继续通行。例如,若村庄按圆周顺序编号为 11 至 66,且已修建小径 11–33、22–44 和 44–66,则除第 55 个村庄外,其余所有村庄均可从第 11 个村庄到达。

给定 mm 个事件的列表,请对每个查询事件,判断此时所给定的两个村庄是否相互可达。

输入格式

The first line contains two integers nn (2≤n≤2⋅1052 \le n \le 2\cdot 10^5) and mm (1≤m≤3⋅1051 \le m \le 3\cdot 10^5) — the number of villages and the number of events respectively.

Next mm lines contain events. Each event description consists of three integers ee (ee is 11 or 22), vv (1≤v≤n1 \le v \le n), and uu (1≤u≤n1 \le u \le n, u≠vu \ne v). If e=1e = 1, then the event is building a trail between villages vv and uu. If e=2e = 2, then the event is a query if the villages vv and uu are connected. It is guaranteed that each trail is built at most once.

Villages are numbered 11 to nn in clockwise order around the circle.

第一行包含两个整数 nn(2≤n≤2⋅1052 \le n \le 2\cdot 10^5)和 mm(1≤m≤3⋅1051 \le m \le 3\cdot 10^5),分别表示村庄的数量和事件的数量。

接下来的 mm 行描述各个事件。每个事件由三个整数 ee(ee 为 11 或 22)、vv(1≤v≤n1 \le v \le n)和 uu(1≤u≤n1 \le u \le n,且 u≠vu \ne v)组成。若 e=1e = 1,则该事件表示在村庄 vv 和 uu 之间修建一条小径;若 e=2e = 2,则该事件为一次查询,询问村庄 vv 和 uu 是否连通。保证每条小径至多被修建一次。

村庄按顺时针顺序编号为 11 至 nn,围成一个圆圈。

输出格式

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.

对于每个查询,如果村庄之间不可达,则输出字符 '0';如果村庄之间可达,则输出 '1'。将所有查询的答案作为单个字符串,在一行中输出。

输入输出样例

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

输入解题思路,AI测评打分。不知道怎么写?

首页