CSU1659: Graph Center(最短路)
Description
The center of a graph is the set of all vertices of minimum eccentricity, that is, the set of all vertices A where the greatest distance d(A,B) to other vertices B is minimal. Equivalently, it is the set of vertices with eccentricity equal to the graph's radius. Thus vertices in the center (central points) minimize the maximal distance from other points in the graph.
------wikipedia
Now you are given a graph, tell me the vertices which are the graph center.
Input
There are multiple test cases.
The first line will contain a positive integer T (T ≤ 300) meaning the number of test cases.
For each test case, the first line contains the number of vertices N (3 ≤ N ≤ 100) and the number of edges M (N - 1 ≤ N * (N - 1) / 2). Each of the following N lines contains two vertices x (1 ≤ x ≤ N) and y (1 ≤ y ≤ N), meaning there is an edge between x and y.
Output
The first line show contain the number of vertices which are the graph center. Then the next line should list them by increasing order, and every two adjacent number should be separated by a single space.
Sample Input
2
4 3
1 3
1 2
2 4
5 5
1 4
1 3
2 4
2 3
4 5
Sample Output
2
1 2
3
1 2 4
HINT
Source
題意: 給出n個點,m條邊,求每個點到其他點的距離,取最大的,然後在這所有最大的距離中選一個最小的值,最後輸出這個值下有哪些點符合條件
思路: n次最短路找出所有答案
#include
#include
#include
#include
#include
#include
#include