Assassin Creed

View as PDF

Submit solution

Points: 1.51 (partial)
Time limit: 3.0s
Memory limit: 512M
Input: stdin
Output: stdout

Problem type
Allowed languages
C, C++, Go, Java, Kotlin, Pascal, PyPy, Python, Rust, Scratch

Ezio needs to kill ~N~ targets located in ~N~ different cities. The cities are connected by some one way roads. As time is short, Ezio can send a massage along with the map to the assassin's bureau to send some assassins who will start visiting cities and killing the targets. An assassin can start from any city, he may visit any city multiple times even the cities that are already visited by other assassins. Now Ezio wants to find the minimum number of assassins needed to kill all the targets.


Input starts with an integer ~T~ ~(\leq 70)~, denoting the number of test cases.

Each case starts with a blank line. Next line contains two integers ~N~ ~(1 \leq N \leq 1000)~ and ~M~ ~(0 \leq M \leq 10000)~, where ~N~ denotes the number of cities and ~M~ denotes the number of one way roads. Each of the next ~M~ lines contains two integers ~u~ ~v~ ~(1 \leq u~, ~v \leq N~, ~u \neq v)~ meaning that there is a road from ~u~ to ~v~. Assume that there can be at most one road from a city ~u~ to ~v~.


For each case, print the case number and the minimum number of assassins needed to kill all targets.

Sample Input


5 4
1 2
1 3
4 1
5 1

7 0

8 8
1 2
2 3
3 4
4 1
1 6
6 7
7 8
8 6

Sample Output

Case 1: 2
Case 2: 7
Case 3: 2


Dataset is huge, use faster I/O methods.


Please read the guidelines before commenting.

  • -3
    bautroidaysao  commented on Sept. 8, 2022, 2:36 p.m.

    cho e hoi testcases 3 phai ra 1 chu nhi :( minh gui mot sat thu o 1 no co the di qua moi diem