Logo
(追記) (追記ここまで)

26423번 - Suspects and Witnesses 서브태스크다국어

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

문제

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

힌트

출처

Contest > Google > Kick Start > Google Kick Start 2022 > Round D D번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /