forked from marioyc/Online-Judge-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1082 - Stockbroker Grapevine.cpp
executable file
·51 lines (40 loc) · 1.13 KB
/
1082 - Stockbroker Grapevine.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include<iostream>
#include<string>
using namespace std;
int main(){
int T[100][100];
int N;
int m,a,b;
int min_time, start;
while(1){
scanf("%d",&N);
if(N==0) break;
for(int i=0;i<N;i++) fill(T[i],T[i]+N,(1<<20));
for(int i=0;i<N;i++) T[i][i]=0;
for(int i=0;i<N;i++){
scanf("%d",&m);
for(int j=0;j<m;j++){
scanf("%d %d",&a,&b);
T[i][a-1]=b;
}
}
for(int k=0;k<N;k++)
for(int i=0;i<N;i++)
for(int j=0;j<N;j++)
T[i][j]=min(T[i][j],T[i][k]+T[k][j]);
min_time=(1<<20);
for(int i=0;i<N;i++){
m=-1;
for(int j=0;j<N;j++){
m=max(m,T[i][j]);
}
if(m<min_time){
start=i;
min_time=m;
}
}
if(min_time==(1<<20)) printf("disjoint\n");
else printf("%d %d\n",start+1,min_time);
}
return 0;
}