시간 제한메모리 제한제출정답맞힌 사람정답 비율
5 초 512 MB3001219035.433%

문제

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:

  • A new bridge between two islands was just built by members of a local tribe.
  • A big pink fluffy acid bear Lug appears and destroys a bridge.
  • Richard asks you to find the safest path between two islands.

입력

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:

  • 0 X Y V : A bridge of danger level V (0 ≤ V < 10) has just been built between islands X and Y .
  • 1 X Y : The bridge connecting islands X and Y has just been destroyed.
  • 2 X Y : Richard asks what is the safest path from island X to island Y .

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.

예제 입력 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
-1
3
-1
3
4
3
-1

예제 입력 2

6 6
0 2 0 4
0 3 4 3
0 0 4 1
0 2 5 4
2 3 2
2 4 2

예제 출력 2

4
4