Capital
Time limit1sMemory limit1024 MB
Count the cities S for which some positive road lengths make every road's A end no farther from S than its B end.
- Level
Medium7 of 10
- Topics
- Graph, Shortest path, Brute force
- Solved
- No attempts yet
Problem
There are cities connected by roads. Cities are numbered from 1 through , and roads are numbered from 1 through . For each pair of cities, there is a sequence of roads that connects them. Road has length kilometres and connects cities and in both directions. Every road has a positive length, so . The lengths of the roads are unknown.
For each road, all people on road travel from to in a single direction. Based on this, the following hypothesis is made:
- There is a capital city .
- People move from the capital to other cities.
- People take the shortest path. So the shortest distance from to is less than or equal to the shortest distance from to .
Find every capital city that satisfies these conditions when each road length can be any positive real number. You may assume that at least one city satisfies the conditions.
Input
The first line contains two integers () and ().
Each of the next lines contains and (). There are no self-loops or multiple edges. That is, , and implies .
Output
On the first line, print the number of possible capital cities .
On the second line, print the possible capital cities in increasing order, separated by spaces.