Tea Time

No attempts yetTime limit1sMemory limit128 MB

Problem

$N$ cows ($1 \le N \le 1000$), conveniently numbered $1 \ldots N$, attend a tea time every day. $M$ ($1 \le M \le 2000$) unique pairs of those cows have already met before the first tea time. Pair $i$ is given by two different integers $A_i$ and $B_i$ ($1 \le A_i \le N$; $1 \le B_i \le N$). The input never lists a pair of cows that have met more than once.

At each tea time, any two cows $i$ and $j$ that have both met a mutual friend cow $k$ will meet during that tea time, expanding their circle of acquaintances.

Tea times are held until no new meetings occur. For each of $Q$ ($1 \le Q \le 100$) queries, determine whether the two cows have met by then. Query $j$ consists of two different cows $X_j$ and $Y_j$ ($1 \le X_j \le N$; $1 \le Y_j \le N$).

For example, suppose that among cows $1$ through $5$ we know that cow $2$ has met cow $5$, cow $2$ has met cow $3$, and cow $4$ has met cow $5$; see (a) below.

   2---3           2---3            2---3
    \              |\  |            |\ /|
1    \     -->  1  | \ |    -->  1  | X |
      \            |  \|            |/ \|
   4---5           4---5            4---5
    (a)             (b)              (c)

In the first tea time, cow $2$ meets cow $4$ and cow $3$ meets cow $5$; see (b). In the second tea time, cow $3$ meets cow $4$; see (c).

Input

  • Line $1$: three space-separated integers $N$, $M$, and $Q$.
  • Lines $2 \ldots M+1$: line $i+1$ contains two space-separated integers $A_i$ and $B_i$.
  • Lines $M+2 \ldots M+Q+1$: line $j+M+1$ contains query $j$ as two space-separated integers $X_j$ and $Y_j$.

Output

  • Lines $1 \ldots Q$: line $j$ should be Y if the two cows in query $j$ have met, or N if they have not.