This page is still under construction.

Parts of this page are still being built. What you see may change.

Telecommunication Partners

Time limit1sMemory limit128 MB

Summary
Given an undirected graph and K, find the largest connected vertex set where each vertex has degree at least K inside the set.
Level

Medium7 of 10

Topics
Graph, Greedy, DFS
Solved
No attempts yet

Problem

An international telecommunication company wants to offer its business subscribers a discount on calls made to a fixed set of telephone numbers chosen by the client. From last year's call records, we say that two companies are Business Partners if one of them made or received a call to or from the other during the year.

Given the partnership relation among the companies and an integer KK, find the size (number of companies) of the largest set SS of companies that satisfies both of the following:

  • Every company in SS has at least KK business partners that are also in SS (it may also have partners outside SS).
  • SS is connected: from any company in SS you can reach any other company in SS by following business-partner relationships that stay within SS.

If no such set exists, the answer is 00.

Input

The input consists of several test cases. The first line of each test case has three integers NN, PP, and KK. NN is the total number of companies subscribed to the service (1≤N≤10001 \le N \le 1000); companies are identified by numbers from 11 to NN. PP is the number of business-partner pairs, and KK is the minimum number of business partners each company must have inside the final set (1≤K≤N−11 \le K \le N-1).

Each of the next PP lines contains two integers XX and YY (1≤X≤N1 \le X \le N, 1≤Y≤N1 \le Y \le N, X≠YX \ne Y), meaning that companies XX and YY are business partners. The same pair may appear on more than one line, but it still counts as a single partnership.

A line whose first integer NN is 00 marks the end of the input.

Output

For each test case, print a single line containing the size of the largest set SS that satisfies the conditions above.

Examples1

  1. Example 1

    Input
    5 3 1
    1 2
    4 3
    4 5
    5 3 2
    1 2
    4 3
    4 5
    10 11 2
    1 2
    1 3
    3 2
    3 5
    5 4
    5 6
    9 10
    8 9
    8 7
    6 7
    6 8
    0 0 0
    
    Expected output
    3
    0
    7