Gossips
Time limit1sMemory limit1024 MB
Given a forest of subgroup relations, answer whether group x knows a gossip about group y as new gossip events spread through ancestors and subgroups.
- Level
Medium7 of 10
- Topics
- Tree, Segment tree, Implementation
- Solved
- No attempts yet
Problem
Poli is in her first year at college. Although she went to one of the best universities, she quickly discovered that her colleagues are split into N friendship groups. The main purpose of these groups is spreading gossip.
Poli knows that each group i is formed out of one or more subgroups, and each subgroup can be a part of only one group. If group i finds a gossip about group j, then all the subgroups of i (and the subgroups of those subgroups, and so on) and all the groups that group i is a part of know the gossip about group j. All of these groups also know the gossip about every group that group j is a part of. They do not know anything about the subgroups of j, because those members may not be implicated in the gossip.
Poli is friends with every one of her colleagues, so she knows when a gossip appears (that is, when a group i finds a gossip about a group j). She wants to answer quickly questions such as: Does group i know a gossip about group j?
Unfortunately Poli's college is rather big, so you have to help her!
Input
The first line contains three integers N (the number of groups), M (the number of relations between the groups), and Q (the number of queries). Each of the next M lines contains a b, meaning group b is a subgroup of group a. Each of the next Q lines contains three integers s, x, and y. If s is 1, answer YES if there is at least one gossip between group x and group y, or NO if not. If s is 2, group x has just found out a gossip about group y.
Output
Print one line for each query of type 1, containing YES or NO.
Constraints
If group i knows a gossip about group j, it does not mean that group j knows a gossip about group i.