21989_MilitaryBases

2022-5-16 18:20| 发布者: Hocassian| 查看: 31| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-4-8950619182700-Problem List-采集的数据-后羿采集器.html

Pro.ID

21989

Title

Military Bases

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=21989

AC

0

Submit

0

Ratio

-

时间&空间限制

  • Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    There are N cities in a country. Some of the cities are connected by one-way roads that do not intersect outside the cities due to a system of bridges and tunnels. It is known that if there are direct roads from cities B and C to city A, then there is also a direct road either from B to C or from C to B. It is additionally known that is it not possible to start from a city and return to the same city after travelling the roads in some way.

    As a part of more general reforms, the head of the state has decided to relocate military bases in the country. He knows that the international community would be alarmed if he would locate any two bases in cities connected by a direct road. He has asked you to help him to find a way to allocate as much military bases as possible without alarming the community.

    输入

    The first line contains N (1 ≤ N ≤ 100000), the number of cities, and M (0 ≤ M ≤ 100000), the number of roads. Each of the following M lines contains two distinct integers from the range 1…N, the numbers of the cities a road connects (we assume the road goes from the first city of the pair to the second). It may be assumed that no two roads connect the same cities and that also the condition described above holds.

    输出

    Description

    There are N cities in a country. Some of the cities are connected by one-way roads that do not intersect outside the cities due to a system of bridges and tunnels. It is known that if there are direct roads from cities B and C to city A, then there is also a direct road either from B to C or from C to B. It is additionally known that is it not possible to start from a city and return to the same city after travelling the roads in some way.

    As a part of more general reforms, the head of the state has decided to relocate military bases in the country. He knows that the international community would be alarmed if he would locate any two bases in cities connected by a direct road. He has asked you to help him to find a way to allocate as much military bases as possible without alarming the community.

    Input

    The first line contains N (1 ≤ N ≤ 100000), the number of cities, and M (0 ≤ M ≤ 100000), the number of roads. Each of the following M lines contains two distinct integers from the range 1…N, the numbers of the cities a road connects (we assume the road goes from the first city of the pair to the second). It may be assumed that no two roads connect the same cities and that also the condition described above holds.

    Output

    The first line of the output should contain K, the maximal number of cities where the bases could be located. The second line should  contain K integers, separated by single spaces, the numbers of cities where the bases should be located. Cities can be listed in any order. If there are several allocation plans with the maximal number of bases, output any one of them.

    Sample Input

    5 7
    1 2
    1 5
    2 4
    3 1
    3 2
    3 5
    5 2

    Sample Output

    2
    3 4

    Source

    样例输入

    5 7
    1 2
    1 5
    2 4
    3 1
    3 2
    3 5
    5 2

    样例输出

    2
    3 4

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部