Limits 2s, 512 MB

Have you heard of the sad story of the place of Banasree? People cannot travel because of the terrible road condition. Students cannot go to their school in time, workers cannot reach their workplaces in time and even lovers cannot meet each other in time which is leading to so many breakups. The entire area is a complete mess which the authority is well aware of. Thus in order to reduce the difficulties that the people of Banasree are facing they have planned up some experiments to conduct on the several roads in the area.

There are NN buildings in Banasree, ranging from residence to police headquarters, each of the buildings have a unique identifier from 1 to NN. Which building is which is not important to us, but it is important to know that there are bidirectional roads which spans from the gate of one building to another. The authority was also intelligent enough to make the road network such that it is possible to travel from any building to any another by means of using some series of roads, and also that the roads do not intersect. Also there is exactly N1N-1 roads, that is the number of roads is one less than the number of buildings.

Initially, before the authority ran any experiments they noted the current traveling time of each road, where traveling time is the average time to travel the entire road once. The authority will now perform Q experiments, and there are two types of them:

Type 1:
A road with number RR (which is numbered by the input order) is selected and have its traveling time permanently changed to value VV until other experiments change this value. It is not necessary that the new traveling time is less than the previous one.

Type 2:
Two buildings with identifier XX and YY are selected and the minimum average time taken to travel between the two buildings are measured.

The experiments will be listed to you in chronological order. For every experiment of Type 2 print the value measured.

Input

The first line of the input contains one integer NN (2N1052 \le N \le 10^5), the number of the buildings in Banasree. Each of the next N1N-1 lines contain three integers each XX and YY (1X,YN1 \le X, Y \le N) and VV (1V1091 \le V \le 10^9), denoting that there is a road with initial traveling time V spanning from the building with identifier XX to the building of identifier YY. Remember that for experiment of Type 1 the selected road will be identified with it’s order in these N1N-1 lines.

The next line contains a single integer QQ (1Q1051 \le Q \le 10^5), the number of experiments conducted. The following QQ line contains three integers each, TT (T={1,2}T= \{1, 2\}), AA and BB,denoting that the experiment is of Type T, and if TT is 1 then AA and BB denotes RR (1RN11 \le R \le N-1) and VV (1V1091 \le V \le 10^9), and if TT is 2 they denote XX and YY (1X,YN1 \le X, Y \le N).

The given input guarantees that it is possible to travel from any building to another, and that the experiments are given in chronological order.

Output

For each experiment of Type 2, print the values that will be measured.

Sample

InputOutput
10
2 6 9
6 10 4
10 7 2
10 3 1
3 1 8
10 9 9
1 4 1
6 5 6
4 8 4
10
1 5 10
2 7 6
1 4 4
2 9 5
1 5 7
1 5 1
2 4 3
1 5 8
2 4 3
2 8 8
6
19
2
9
0

Submit

Login to submit.

Statistics

88% Solution Ratio
partha_mbstuEarliest, May '18
ash_98Fastest, 0.1s
serotoninLightest, 16 MB
serotoninShortest, 1621B
Toph uses cookies. By continuing you agree to our Cookie Policy.