시간 제한메모리 제한제출정답맞힌 사람정답 비율
40 초 (추가 시간 없음) 1024 MB87685.714%

문제

Ada baked some cookies for her birthday party where she invited $\mathbf{N}$ guests, labeled $1$ to $\mathbf{N}$. When all the guests have arrived and the party is about to start, something terrible has happened — someone stole the cookies!

Ada puts on her detective hat and starts questioning her guests. She gathered $\mathbf{M}$ witness statements of the form: Guest x: "Guest y did not steal the cookies."

Ada knows that, if a guest is innocent (did not steal a cookie), then all their witness statements must be true. Note that Ada does not know whether any statement made by a cookie stealer is correct.

Lastly, Ada has an informant who told her there can be at most $\mathbf{K}$ cookie stealers. With this information, can you help Ada find out the number of guests who can be proved to be innocent?

Note that it is possible that no guest actually stole the cookies, and Ada simply forgot how many cookies she baked.

입력

The first line of the input gives the number of test cases, $\mathbf{T}$. $\mathbf{T}$ test cases follow.

The first line of each test case contains three integers $\mathbf{N}$, $\mathbf{M}$, and $\mathbf{K}$: the number of guests, the number of witness statements, and the maximum number of cookie stealers, respectively.

The next $\mathbf{M}$ lines describe the witness statements. The $i$-th line contains two integers $\mathbf{A_i}$ and $\mathbf{B_i}$, which means the witness statement Guest $\mathbf{A_i}$: "Guest $\mathbf{B_i}$ did not steal the cookies."

출력

For each test case, output one line containing Case #$x$: $y$, where $x$ is the test case number (starting from 1) and $y$ is the number of guests that can be proved to be innocent.

제한

  • $1 \le \mathbf{T} \le 100$.
  • $2 \le \mathbf{N} \le 10^5$.
  • $1 \le \mathbf{M} \le 10^5$.
  • $1 \le \mathbf{A_i} \le \mathbf{N}$, for all $i$.
  • $1 \le \mathbf{B_i} \le \mathbf{N}$, for all $i$.
  • $\mathbf{A_i} \neq \mathbf{B_i}$, for all $i$.
  • $(\mathbf{A_i}, \mathbf{B_i}) \neq (\mathbf{A_j}, \mathbf{B_j})$, for all $i \neq j$.

Test Set 1 (15점)

  • $\mathbf{K} = 1$.

Test Set 2 (27점)

  • $1 \le \mathbf{K} \le 20$.

예제 입력 1

2
3 2 1
1 2
2 3
3 3 1
1 2
2 3
3 1

예제 출력 1

Case #1: 2
Case #2: 3

In Sample Case #1, there are $\mathbf{N}=3$ guests, $\mathbf{M}=2$ witness statements and at most $\mathbf{K}=1$ cookie stealer. The witness statements are:

  • Guest $1$: Guest $2$ did not steal the cookies.
  • Guest $2$: Guest $3$ did not steal the cookies.

Now we consider all possible arrangements on whether each guest is a cookie stealer.

Guest 1 Guest 2 Guest 3 Possible?
Scenario #1 Innocent Innocent Innocent YES
Scenario #2 CS Innocent Innocent YES
Scenario #3 Innocent CS Innocent NO
Scenario #4 Innocent Innocent CS NO

These are all the scenarios where there is at most $\mathbf{K}=1$ cookie stealer (CS). Scenario #3 is impossible because Guest 1 is innocent and states that Guest 2 is innocent, but Guest 2 turns out to be the cookie stealer. Same reasoning for scenario #4.

For the remaining scenarios, we see that Guest 2 and 3 are always innocent, so the answer is $2$.

예제 입력 2

2
3 2 2
1 2
2 3
3 3 2
1 2
2 3
3 2

예제 출력 2

Case #1: 1
Case #2: 2

채점 및 기타 정보

  • 예제는 채점하지 않는다.