import java.util.Scanner;
public class 多源最短路径算法 {
/*
* 输入第1行给出两个正整数N (≤100)和M,其中N是考试涉及的动物总数,
* M是用于直接变形的魔咒条数。为简单起见,我们将动物按1~N编号。随后M行,
* 每行给出了3个正整数,分别是两种动物的编号、以及它们之间变形需要的魔咒的长度
* 数字之间用空格分隔。
输出格式:
输出哈利·波特应该带去考场的动物的编号、以及最长的变形魔咒的长度,中间以空格分隔。
如果只带1只动物是不可能完成所有变形要求的,则输出0。如果有若干只动物都可以备选,
则输出编号最小的那只。
6 11
3 4 70
1 2 1
5 4 50
2 6 50
5 6 60
1 3 70
4 6 60
3 6 80
5 1 100
2 4 60
5 2 80
*/
static int N;
static int E;
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
N = in.nextInt();//动物数
E = in.nextInt();//有E行数据
int G [][] = new int[N][N];//初始化图,无穷大
for(int i =0; i<N; i++) {
for(int j = 0; j<N; j++) {
G[i][j] = Integer.MAX_VALUE/10;
//防止弗洛伊德算法出现相加溢出
}
}
for(int i=0;i<E;i++) { //插入边
int m = in.nextInt()-1;//起点
int n = in.nextInt()-1;//中间点
int weight = in.nextInt();//代价值
G[m][n] = weight;
G[n][m] = weight;
}
for(int k = 0;k<N;k++) //Floyd算法,更新了最短路径矩阵D
for(int i =0;i<N;i++)
for(int j = 0;j<N; j++) {
G[i][j]=Math.max(G[i][j], G[i][k]+G[k][j]);
}
int temp = Integer.MIN_VALUE;
int dist [] = new int[N];
for(int i =0; i<N;i++ ) {//求出D矩阵每一行中的最大值,存储在 len矩阵中
for(int j = 0;j<N;j++) {//咒语的最大长度
if(G[i][j]>temp&&j!=i) {
temp = G[i][j];
}
}
dist[i] = temp;
temp = Integer.MIN_VALUE;
}
int res = Integer.MAX_VALUE/10;//代表路径
int V = -1;//代表某只动物
for(int i = 0; i<N; i++) {
if(dist[i]<res) {
res = dist[i];
V = i;
}
}
if(V<0)
System.out.print(0);
else
System.out.print((V+1)+" "+res);
}
}`