luogu#P5064. [Ynoi Easy Round 2014] 等这场战争结束之后
[Ynoi Easy Round 2014] 等这场战争结束之后
Background
Can I really become stronger?

【Even if you don’t want to, I will force you to become stronger.】
Then, thanks for your kindness, I’ll say it directly.

Well...
I don’t want to become stronger at all~!
【Then how about this: as long as you come back alive from the battlefield.】
【I can promise you any one request, anything at all.】
Huh?

【Marriage is of course out of the question.】
You said anything...

Desserts...
Didn’t you make desserts in the cafeteria before?
Then, can you make butter cake?

My older sister... that is, among the seniors,
there is someone who, every time she comes back alive from the battlefield,
will taste butter cake with a blissful look on her face.
So... please.
【Of all things, you picked this...】
【No problem. I’ll make you eat until you throw up.】
【So, you must come back alive.】
Problem Description
You are given a graph. Each vertex has a weight, and initially there are no edges.
There are some operations:
- Add an undirected edge between and .
- Revert to the state after the -th operation (note that can be , which means reverting to the initial state).
- Query the -th smallest vertex weight among the vertices reachable in the connected component containing . If it does not exist, output .
Input Format
The first line contains two integers , meaning there are vertices and operations.
The next line contains numbers, giving the weight of each vertex.
Then follow lines, each being one of the following three types:
1 x y
2 x
3 x y
Their meanings are as described in the statement.
Output Format
For every operation of type , output one line containing one integer, which is the answer.
6 10
816801151 223885531 110182151 94271893 319888699 106363731
1 1 3
1 3 5
1 2 4
1 4 6
1 1 2
3 1 1
2 4
1 1 2
3 1 4
2 7
94271893
223885531
Hint
Idea: nzhtl1477.
Solution: nzhtl1477( Time , Space ),ccz181078( Time , Space ) ,shadowice1984( Time , Space ) , zx2003( Time , Space ).
Code: nzhtl1477( Time , Space ),ccz181078( Time , Space ) ,shadowice1984( Time , Space ),zx2003( Time , Space ).
Data: nzhtl1477( partially uploaded ).
Constraints: for of the testdata, and .
Translated by ChatGPT 5