传统题 1000ms 256MiB

A-3 Finding Independent Set

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

Given a simple undirected graph G=(V,E)G=(V, E) . Anindependent 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 vv into SS.
  2. Delete all the vertices (and all the edges incident on them) that are adjacent to vv from GG.
  3. Repeat steps 1 and 2 until there is no un-visited vertex left in GG.

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

输入格式

Each input file contains one test case. For each case, the first line contains 2 positive integers: nn ( 1000\le 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 1 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 1 space. There must be no extra space at the beginning or the end of the line.

题目示例数据

8 7
1 5
5 4
4 2
2 3
3 6
6 1
6 2
1 2 7 8

PAT2024秋季重现赛

未参加
状态
已结束
规则
IOI
题目
11
开始于
2025-8-3 14:00
结束于
2025-8-3 17:30
持续时间
3.5 小时
主持人
参赛人数
51