무향 그래프가 주어질 때, 각 도로의 방향이 S로부터의 거리가 작은 쪽에서 큰 쪽으로 향하도록 양의 실수 길이를 정할 수 있는 시작 도시 S를 모두 찾는다.
어려움8그래프BFS그리디구현아직 제출이 없습니다시간 제한1초메모리 제한1024 MBYou are given N cities connected by M roads. Cities are numbered from 1 through N, and roads are numbered from 1 through M. For each pair of cities, there is a sequence of roads that connects those two cities. Road i has the length L_i kilometre and connects city A_i and city B_i bidirectionally. Every road has a positive length, so L_i>0. Unfortunately, you have forgotten the length of each road.
You observed that, for each road, all people on road i are going from A_i to B_i, in a single direction. So, you assumed the hypothesis as follows:
Can you find the capital city S 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 N (2≤N≤500) and M (N−1≤M≤2N(N−1)).
In the i-th line of next M lines, A_i and B_i are given. (1≤A_i, B_i≤N)
There are no loops or multiple edges. Formally, A_i=B_i, and A_i, B_i=A_j, B_j⟹i=j.
In the first line, print the number of possible capital cities, K.
In the second line, print K space-separated integers which denotes all possible cities for the capital, in increasing order.