: I raised the TL to 2 seconds to avoid fast I/O nonsense. I was able to get AC (very close though) using cin/cout.
There are
Now there will be
Now we want to know the number of cities that COULD BE visited during a parade. Notice that roads built for the exclusive use of a parade do not have to satisfy the property satisfied by the roads originally in the country.
Input Specification
The first line contains four integers
In the following
In the next
It is guaranteed if we treat the one-way roads originally in the country as bidirectional, the cities are mutually reachable.
Output Specification
For each query, output an integer in a line denoting the answer. If it is not possible to reach the destination from the origin, output 0.
Sample Input 1
5 6 4 1
1 2
1 3
1 4
2 5
4 5
5 4
1 4 5 1
2 3 5 3
1 2 5 2
3 4 5 1
Sample Output 1
4
4
4
0
Explanation for Sample Output 1
In parade 1, the origin is city 1 and the destination is city 4. The
temporary road is
In parade 2, the origin is city 2 and the destination is city 3. The
temporary road is
In parade 3, the origin is city 1 and the destination is city 2. The
temporary road is
In parade 4, the origin is city 3 and the destination is city 4. The
temporary road is
Additional Samples
Sample inputs and outputs can be found here.
- Sample 2 (
celebration2.in
andcelebration2.ans
) corresponds to cases 5-7. - Sample 3 (
celebration3.in
andcelebration3.ans
) corresponds to cases 10-11. - Sample 4 (
celebration4.in
andcelebration4.ans
) corresponds to cases 15-16. - Sample 5 (
celebration5.in
andcelebration5.ans
) corresponds to cases 20-25.
Constraints
For all test cases,
Test Case | Additional Constraints | ||
---|---|---|---|
1~4 | None. | ||
5~7 | |||
8~9 | |||
10~11 | |||
12~14 | |||
15~16 | None. | ||
17~19 | |||
20~25 |
Comments