#P14615. [2019 KAIST RUN Fall] Capital

[2019 KAIST RUN Fall] Capital

题目描述

You are given NN cities connected by MM roads. Cities are numbered from 1 through NN, and roads are numbered from 1 through MM. For each pair of cities, there is a sequence of roads that connects those two cities. Road ii has the length LiL_i kilometre and connects city AiA_i and city BiB_i bidirectionally. Every road has a positive length, so Li>0L_i > 0. Unfortunately, you have forgotten the length of each road.

You observed that, for each road, all people on road ii are going from AiA_i to BiB_i, in a single direction. So, you assumed the hypothesis as follows:

  • There is a capital city called SS.
  • People are moving from the capital city to other cities.
  • People try to move in the shortest path. So the length of the shortest path from SS to AiA_i is less than or equal to the length of the shortest path from SS to BiB_i.

Can you find the capital city SS which meets the criteria when you can assign the length of each road to be any positive real number? You may assume that there is at least one city that meets the criteria.

输入格式

The first line of the input contains two integers NN (2N5002 \le N \le 500) and MM (N1MN(N1)2N-1 \le M \le \frac{N(N-1)}{2}).

In the ii-th line of next MM lines, AiA_i and BiB_i are given. (1Ai,BiN1 \le A_i, B_i \le N)

There are no loops or multiple edges. Formally, AiBiA_i \ne B_i, and {Ai,Bi}={Aj,Bj}    i=j\{A_i, B_i\} = \{A_j, B_j\} \implies i = j.

输出格式

In the first line, print the number of possible capital cities, KK.

In the second line, print KK space-separated integers which denotes all possible cities for the capital, in increasing order.

2 1
1 2
1
1