#abc350g. G - Mediator
G - Mediator
Score: points
问题陈述
注意特殊的输入格式和比平时更小的内存限制。
有一个无向图,顶点为 ,最初没有边。
你需要处理这个图上的 个查询:
1 $u$ $v$
类型 :在顶点 和 之间添加一条边。
在添加边之前, 和 属于不同的连通分量(即,图始终保持为森林)。
2 $u$ $v$
类型 :如果存在一个顶点与 和 都相邻,则报告其顶点编号;否则,报告 。
鉴于图始终保持为森林,这个查询的答案唯一确定。
查询以加密形式给出。
原始查询由三个整数 定义,加密查询由三个整数 给出。
让 是第 个类型- 查询的答案。定义 对于 。
根据给定的 恢复 如下:
- 让 是此查询之前给出的类型- 查询的数量(不包括查询本身)。然后,使用以下方法:
- $A = 1 + (((a \times (1+X_l)) \mod 998244353) \mod 2)$
- $B = 1 + (((b \times (1+X_l)) \mod 998244353) \mod N)$
- $C = 1 + (((c \times (1+X_l)) \mod 998244353) \mod N)$
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
Beware the special input format and the smaller memory limit than usual.
There is an undirected graph with vertices , initially without edges.
You need to process the following queries on this graph:
1 $u$ $v$
Type : Add an edge between vertices and .
Before adding the edge, and belong to different connected components (i.e., the graph always remains a forest).
2 $u$ $v$
Type : If there is a vertex adjacent to both and , report its vertex number; otherwise, report .
Given that the graph always remains a forest, the answer to this query is uniquely determined.
The queries are given in an encrypted form.
The original query is defined by three integers , and the encrypted query is given as three integers .
Let be the answer to the -th type- query. Define for .
Restore from the given as follows:
- Let be the number of type- queries given before this query (not counting the query itself). Then, use the following:
- $A = 1 + (((a \times (1+X_l)) \mod 998244353) \mod 2)$
- $B = 1 + (((b \times (1+X_l)) \mod 998244353) \mod N)$
- $C = 1 + (((c \times (1+X_l)) \mod 998244353) \mod N)$
Constraints
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Let be the number of type- queries. Print lines.
The -th line should contain the answer to the -th type- query.
Sample Input 1
6 12
143209915 123840720 97293110
89822758 207184717 689046893
67757230 270920641 26993265
952858464 221010240 871605818
730183361 147726243 445163345
963432357 295317852 195433903
120904472 106195318 615645575
817920568 27584394 770578609
38727673 250957656 506822697
139174867 566158852 412971999
205467538 606353836 855642999
159292205 319166257 51234344
Sample Output 1
0
2
0
2
6
0
1
After decrypting all queries, the input is as follows:
6 12
2 1 3
1 2 6
1 2 4
1 1 3
2 4 6
2 1 4
1 5 6
1 1 2
2 1 4
2 2 5
2 3 4
2 2 3
This input has a -vertex graph and queries.
- The first query is
2 1 3
.- No vertex is adjacent to both vertex and vertex , so report .
- The second query is
1 2 6
.- Add an edge between vertices and .
- The third query is
1 2 4
.- Add an edge between vertices and .
- The fourth query is
1 1 3
.- Add an edge between vertices and .
- The fifth query is
2 4 6
.- The vertex adjacent to both vertices and is vertex .
- The sixth query is
2 1 4
.- No vertex is adjacent to both vertices and , so report .
- The seventh query is
1 5 6
.- Add an edge between vertices and .
- The eighth query is
1 1 2
.- Add an edge between vertices and .
- The ninth query is
2 1 4
.- The vertex adjacent to both vertices and is vertex .
- The tenth query is
2 2 5
.- The vertex adjacent to both vertices and is vertex .
- The eleventh query is
2 3 4
.- No vertex is adjacent to both vertices and , so report .
- The twelfth query is
2 2 3
.- The vertex adjacent to both vertices and is vertex .
Sample Input 2
2 1
377373366 41280240 33617925
Sample Output 2
The output may be empty.