#abc225d. D - Play Train
D - Play Train
Score : points
问题描述
高桥正在玩玩具火车,连接和断开它们。 共有 辆玩具火车车厢,编号分别为:车1、车2、……、车。 最初,所有车厢都是分开的。
你将收到 个查询请求,请按照给定顺序处理。查询有三种类型,如下所示:
-
1 x y
:将车的前端与车的后端连接起来。
确保满足以下条件:- 在此查询之前,没有火车连接到车的后端;
- 在此查询之前,没有火车连接到车的前端;
- 在此查询之前,车和车属于不同的连通分量。
-
2 x y
:将车的前端从车的后端断开连接。
确保满足以下条件:- ;
- 在此查询之前,车的前端直接连接到车的后端。
-
3 x
:打印包含车的连通分量中车厢的编号,从前到后。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
Takahashi is playing with toy trains, connecting and disconnecting them.
There are toy train cars, with car numbers: Car , Car , , Car .
Initially, all cars are separated.
You will be given queries. Process them in the order they are given. There are three kinds of queries, as follows.
-
1 x y
: Connect the front of Car to the rear of Car .
It is guaranteed that:- just before this query, no train is connected to the rear of Car ;
- just before this query, no train is connected to the front of Car ;
- just before this query, Car and Car belong to different connected components.
-
2 x y
: Disconnect the front of Car from the rear of Car .
It is guaranteed that:- ;
- just before this query, the front of Car is directly connected to the rear of Car .
-
3 x
: Print the car numbers of the cars belonging to the connected component containing Car , from front to back.
Constraints
- All values in input are integers.
- All queries satisfy the conditions in the Problem Statement.
- The queries of the format
3 x
ask to print at most car numbers in total.
Input
Input is given from Standard Input in the following format:
The -th query begins with an integer (, , or ) representing the kind of the query, followed by and if or , and followed by if .
In short, each query is in one of the following three formats:
Output
If a query with asks to print the values , output the following line:
Your output should consist of lines, where is the number of queries with .
The -th line should contain the response to the -th such query.
Sample Input 1
7 14
1 6 3
1 4 1
1 5 2
1 2 7
1 3 5
3 2
3 4
3 6
2 3 5
2 4 1
1 1 5
3 2
3 4
3 6
Sample Output 1
5 6 3 5 2 7
2 4 1
5 6 3 5 2 7
4 1 5 2 7
1 4
2 6 3
The figure below shows the cars when the first queries are processed.
For example, Car belongs to the same connected component as Cars , which is different from the connected component containing Cars .
The figure below shows the cars when the first queries are processed.
update @ 2024/3/10 09:53:22