Championships
Time limit1.5sMemory limit256 MB
Find the largest set S of vertices such that the induced subgraph on S is connected and every vertex in S has degree at least d within S.
- Level
Hard8 of 10
- Topics
- Graph, Greedy, BFS, Implementation
- Solved
- No attempts yet
Problem
The Computer Sports World Championships are the most important event in the calendar of every electronic entertainment fan. This year, the championships will be held in the kingdom of Byteotia. The organizing committee, appointed by King Byteasar, faces a difficult task: it has to decide in which Byteotian cities the competitions will take place. Byteotia has cities (numbered through ) connected by two-way roads.
The committee hopes that the championship will attract crowds of fans from all over the world. Naturally, fans will travel frequently between the cities to watch the competitions of various e-sport types. The priority is therefore that the set of cities hosting the championship events is well connected.
We call a set of cities well connected if:
- From every city of the set there are at least direct connections to other cities of .
- Between any two cities of there exists a route running only through the cities belonging to the set .
Additionally, to minimize the average number of visitors in each city, the committee would prefer the chosen set to be as large as possible.
Input
The first line of the input contains three integers , and (, , ) denoting the number of cities, the number of roads in Byteotia and the parameter , respectively. The next lines describe the Byteotian roads. The -th of these lines contains two integers and (, ) indicating that the -th road connects the cities numbered and . Each pair of cities is connected by at most one direct road.
Output
If it is not possible to choose a set of cities of Byteotia that is well connected, the only line of the output should contain the word "NIE" (Polish for no).
Otherwise, the output should contain the most numerous set of cities that is well connected, in the following format. The first line should contain the number denoting the size of the found set. The second line should contain numbers representing the cities belonging to the set, in ascending order.
In case there are multiple solutions, your program can output any of them.