6995.Forbidden Cities

Time Limit: 4s Memory Limit: 512MB

There are $n$ cities and $m$ roads between them. Kaaleppi is currently in city $a$ and wants to travel to city $b$ .

However, there is a problem: Kaaleppi has recently robbed a bank in city $c$ and can't enter the city, because the local police would catch him. Your task is to find out if there is a route from city $a$ to city $b$ that does not visit city $c$ .

As an additional challenge, you have to process $q$ queries where $a$ , $b$ and $c$ vary.

Input Format(From the terminal/stdin)

The first input line has three integers $n$ , $m$ and $q$ : the number of cities, roads and queries. The cities are numbered $1,2,\dots,n$ .

Then, there are $m$ lines describing the roads. Each line has two integers $a$ and $b$ : there is a road between cities $a$ and $b$ . Each road is bidirectional.

Finally, there are $q$ lines describing the queries. Each line has three integers $a$ , $b$ and $c$ : is there a route from city $a$ to city $b$ that does not visit city $c$ ?

You can assume that there is a route between any two cities.

  • $1 \le n \le 10^5$
  • $1 \le m \le 2 \cdot 10^5$
  • $1 \le q \le 10^5$
  • $1 \le a,b,c \le n$

Output Format(To the terminal/stdout)

For each query, print "YES", if there is such a route, and "NO" otherwise.

Sample Input

Copy
5 6 3
1 2
1 3
2 3
2 4
3 4
4 5
1 4 2
3 5 4
3 5 2
 · · \n
 · \n
 · \n
 · \n
 · \n
 · \n
 · \n
 · · \n
 · · \n
 · · \n

Sample Output

Copy
YES
NO
YES
   \n
  \n
   \n
Source: CSES, Advanced Graph Problems, 1705

Submit

请先 登录

© 2025 FAQs