Alice and wheel-graph

0

0 votes
Algorithms, Graphs, Medium
Problem

Alice has a wheel-graph: an undirected graph with n+1 nodes and 2n edges. In wheel-graph there are edges between n+1 and i for each integer i:1in and edges between i and imodn+1 for each integer i:1<=i<=n (see examples to understand it better). Undirected graphs are quite boring for Alice so she made a directed wheel-graph and now each edge has a direction.

Alice wants performs two types of queries:

  • 1 a b - change orientation between nodes a and b. Now orientation is from a to b (before this query in graph was a edge from node b to node a).
  • 2 a b - check if is b reachable from a.

Help her.

INPUT
The first line of the input contains a single integer n (2n200000) - number of nodes without center node.

Then follow n2 lines with edges description. The i-th of these lines contains two integers ai and bi - index of node the edge start from, index of node the edge goes to. It is guaranteed that edges formed a correct directed wheel-graph with n+1 nodes.

Next line of the input contains a single integer q (1q200000) - number of queries.

Then q lines follow with queries description. The i-th of these lines contains three integers typei, ai, bi - parameters of the i-th query.

OUTPUT
For each query of the second type print "Yes" if b can be reached from a and "No" otherwise.

Sample Input
3
1 2
1 3
1 4
2 4
4 3
3 2
5
2 1 2
2 2 1
1 3 1
2 2 1
2 4 1
Sample Output
Yes
No
Yes
Yes
Time Limit: 3
Memory Limit: 256
Source Limit:
Explanation

Graph before change Graph before change

Graph after change in the third query 
Graph after change in the third query

Editor Image

?