시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
3.5 초 | 1024 MB | 13 | 3 | 3 | 23.077% |
Pablo is one of the most notorious men in the Wild West, well known for his influence upon N cities interconnected by roads forming a tree structure. Pablo's trusted men are traffickers, transporting merchandise relentlessly. Each trafficker is defined by a pair a cities (u, v) as follows: the trafficker travels starting with time 0 from city u towards city v, on the shortest path. At each integer moment of time each trafficker delivers one unit of merchandise, then moves on to the next city.
Pablo's traffickers are not easy to track: once a trafficker reaches his destination city v and delivers the merchandise, at the next moment of time he teleports back to city u (if at time t he delivers merchandise in city v, then at time t + 1 he will deliver in city u). As business is flourishing and it would be a shame for it to stop, the traffickers will follow their routes forever.
Although the system put in place by Pablo seems unbreachable, he wonders whether there is any room for improvement. Thus, he will perform 3 types of queries over the system:
The first line contains N, the number of cities. The following N - 1 lines contain 2 integers u and v each, signifying that there is a direct road between cities u and v.
The next line contains K, the number of traffickers initially present in Pablo's network. The following K lines each contain 2 numbers u and v, the pair of cities defining the path of a trafficker.
The next line contains Q, the number of queries Pablo intends to perform. The following Q lines each contain a query in the format mentioned above.
For each query of type 3 output the answer on a separate line.
none
5 1 2 2 3 2 4 1 5 1 4 1 3 3 3 5 0 3 1 2 5 3 4 5 1 5
2 10