시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
5 초 | 512 MB | 281 | 115 | 84 | 35.146% |
In a very distant land called Midsommer, there is a cute little river delta. Deep purple acid flows in the river, so it is impossible to swim there. There are several islands in the delta and bridges connecting some pairs of them. Every bridge is assigned a danger level, which measures how dangerous it is to travel across that bridge, higher levels being more dangerous.
A detective, and as matter of coincidence also a mystery novels author, Richard Hradecki often needs to travel between the islands to pursue his detective cases. Among all possible paths, he prefers to choose the safest one, which means the highest danger level of a bridge on the path must be as low as possible.
For planning purposes, Richard usually asks you to find him the safest path from one island to another island where he is investigating. To be able to satisfy his requests, you have to continuously register three types of events:
The first line of input contains two integers N and Q (2 ≤ N ≤ 105 and 1 ≤ Q ≤ 105). N is the number of islands (which are labeled 0, 1, . . . , N − 1) and Q is the number of events to follow.
Each of the next Q lines represents one event and it contains three or four integers, interpreted as follows:
For all types of events, X and Y denote a valid pair of islands (0 ≤ X, Y < N and X ≠ Y ). There is always at most one bridge between any pair of islands. A bridge to be destroyed always exists at that moment.
For each event of type 2, output a line with the danger level of the most dangerous bridge on the safest path from X to Y . If there is no path between X and Y , output −1.
6 15 0 1 2 1 2 1 4 2 1 5 0 2 3 2 2 1 4 2 1 5 0 3 4 3 2 1 4 2 1 5 0 4 5 4 2 1 4 2 1 5 1 4 5 2 1 4 2 1 5
-1 -1 -1 -1 3 -1 3 4 3 -1
6 6 0 2 0 4 0 3 4 3 0 0 4 1 0 2 5 4 2 3 2 2 4 2
4 4
ICPC > Regionals > Europe > Central European Regional Contest > CERC 2018 B번