Under construction

Still being built. Things may change

Suspects and Witnesses

Interview

Time limit40sMemory limit1024 MB

Summary
Given witness statements that name innocent guests and a cap K on stealers, count the guests who are innocent in every consistent scenario.
Level

Medium6 of 10

Topics
Graph, BFS
Solved
No attempts yet

Problem

Ada baked some cookies for her birthday party, where she invited N\mathbf{N} guests, labeled 11 to N\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 questions her guests. She gathered M\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. Ada does not know whether any statement made by a cookie stealer is correct.

An informant told her there are at most K\mathbf{K} cookie stealers. Using this information, find the number of guests who can be proved to be innocent.

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

Input

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

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

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

Output

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

Limits

  • 1≤T≤1001 \le \mathbf{T} \le 100.
  • 2≤N≤1052 \le \mathbf{N} \le 10^5.
  • 1≤M≤1051 \le \mathbf{M} \le 10^5.
  • 1≤A_i≤N1 \le \mathbf{A\_i} \le \mathbf{N}, for all ii.
  • 1≤B_i≤N1 \le \mathbf{B\_i} \le \mathbf{N}, for all ii.
  • A_i≠B_i\mathbf{A\_i} \neq \mathbf{B\_i}, for all ii.
  • (A_i,B_i)≠(A_j,B_j)(\mathbf{A\_i}, \mathbf{B\_i}) \neq (\mathbf{A\_j}, \mathbf{B\_j}), for all i≠ji \neq j.

Examples1

  1. Example 1

    Input
    2
    3 2 1
    1 2
    2 3
    3 3 1
    1 2
    2 3
    3 1
    
    Expected output
    Case #1: 2
    Case #2: 3