#P1324. Finding Independent Set
Finding Independent Set
Finding Independent Set
题目描述
Given a simple undirected graph . An independent set of is a set such that no two members of are connected by an edge in . Finding the maximum independent set of is an NP-hard problem. Here you are supposed to implement a greedy hueristic to find a near-maximum independent set. The algorithm works in the following way:
- Collect any one un-visited vertex v into .
- Delete all the vertices (and all the edges incident on them) that are adjacent to from .
- Repeat steps and until there is no un-visited vertex left in .
In order to obtain the unique solution, when there are many options in step , you must always choose the vertex with the smallest index.
输入格式
Each input file contains one test case. For each case, the first line contains positive integers: (), the number of vertices; and , the number of edges. Then lines follow, each gives indices of the two ends of an edge. The vertices are indexed from to .
输出格式
Print in a line the indices of the vertices in the independent set obtained by the given greedy algorithm. The indices must be in increasing order, and must be separated by exactly space. There must be no extra space at the beginning or the end of the line.
样例 #1
样例输入 #1
8 7
1 5
5 4
4 2
2 3
3 6
6 1
6 2
样例输出 #1
1 2 7 8