Rating changes for last rounds are temporarily rolled back. They will be returned soon. ×

slow_coder4's blog

By slow_coder4, history, 7 years ago, In English

problem :http://www.lightoj.com/volume_showproblem.php?problem=1111.. why its WA. Give me some critical case..

problem: K people are having a picnic. They are initially in N cities, conveniently numbered from 1 to N. The roads between cities are connected by M one-way roads (no road connects a city to itself).

Now they want to gather in the same city for their picnic, but (because of the one-way roads) some people may only be able to get to some cities. Help them by figuring out how many cities are reachable by all of them, and hence are possible picnic locations.

Input Input starts with an integer T (≤ 10), denoting the number of test cases.

Each case starts with three integers K (1 ≤ K ≤ 100), N (1 ≤ N ≤ 1000), M (1 ≤ M ≤ 10000). Each of the next K lines will contain an integer (1 to N) denoting the city where the ith person lives. Each of the next M lines will contain two integers u v (1 ≤ u, v ≤ N, u ≠ v) denoting there is a road from u to v.

Output For each case, print the case number and the number of cities that are reachable by all of them via the one-way roads.

Sample Input 1 2 4 4 2 3 1 2 1 4 2 3 3 4 Output for Sample Input Case 1: 2

  • Vote: I like it
  • +8
  • Vote: I do not like it

| Write comment?
»
7 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

1
1 3 1
2
2 3

Answer should be 2. (Cities 2 and 3 can be visited.)