#P1324. Finding Independent Set

Finding Independent Set

Finding Independent Set

题目描述

Given a simple undirected graph G=(V,E)G=(V,E). An independent set of GG is a set SVS \subseteq V such that no two members of SS are connected by an edge in EE . Finding the maximum independent set of GG 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:

  1. Collect any one un-visited vertex v into SS .
  2. Delete all the vertices (and all the edges incident on them) that are adjacent to vv from GG.
  3. Repeat steps 11 and 22 until there is no un-visited vertex left in GG.

In order to obtain the unique solution, when there are many options in step 11, you must always choose the vertex with the smallest index.

输入格式

Each input file contains one test case. For each case, the first line contains 22 positive integers: nn (1000≤1000), the number of vertices; and mm, the number of edges. Then mm lines follow, each gives indices of the two ends of an edge. The vertices are indexed from 11 to nn.

输出格式

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 11 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