#P16884. [GKS 2022 #D] Suspects and Witnesses

    ID: 17130 Type: RemoteJudge 5000ms 1024MiB Tried: 0 Accepted: 0 Difficulty: 5 Uploaded By: Tags>搜索2022Google Kick Start

[GKS 2022 #D] Suspects and Witnesses

题目描述

Ada baked some cookies for her birthday party where she invited NN guests, labeled 11 to NN. 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 MM witness statements of the form: Guest xx: "Guest yy 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 KK 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, TT. TT test cases follow.

The first line of each test case contains three integers NN, MM, and KK: the number of guests, the number of witness statements, and the maximum number of cookie stealers, respectively.

The next MM lines describe the witness statements. The ii-th line contains two integers AiA_i and BiB_i, which means the witness statement Guest AiA_i: "Guest BiB_i did not steal the cookies."

输出格式

For each test case, output one line containing Case #xx: yy, where xx is the test case number starting from 11 and yy is the number of guests that can be proved to be innocent.

2
3 2 1
1 2
2 3
3 3 1
1 2
2 3
3 1
Case #1: 2
Case #2: 3

2
3 2 2
1 2
2 3
3 3 2
1 2
2 3
3 2
Case #1: 1
Case #2: 2

提示

In Sample Case #11, there are N=3N = 3 guests, M=2M = 2 witness statements and at most K=1K = 1 cookie stealer.

The witness statements are:

  • Guest 11: Guest 22 did not steal the cookies.
  • Guest 22: Guest 33 did not steal the cookies.

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

Scenario Guest 11 Guest 22 Guest 33 Possible?
Scenario #11 Innocent Innocent Innocent YES
Scenario #22 CS
Scenario #33 Innocent CS NO
Scenario #44 Innocent CS

These are all the scenarios where there is at most K=1K = 1 cookie stealer (CS). Scenario #33 is impossible because Guest 11 is innocent and states that Guest 22 is innocent, but Guest 22 turns out to be the cookie stealer. Same reasoning for scenario #44.

For the remaining scenarios, we see that Guest 22 and Guest 33 are always innocent, so the answer is 22.

Limits

1≤T≤1001 \le T \le 100.

2≤N≤1052 \le N \le 10^5.

1≤M≤1051 \le M \le 10^5.

1≤Ai≤N1 \le A_i \le N, for all ii.

1≤Bi≤N1 \le B_i \le N, for all ii.

Ai≠BiA_i \ne B_i, for all ii.

(Ai,Bi)≠(Aj,Bj)(A_i, B_i) \ne (A_j, B_j), for all i≠ji \ne j.

Test Set 11

K=1K = 1.

Test Set 22

1≤K≤201 \le K \le 20.