-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1389_acm.cpp
63 lines (44 loc) · 1.02 KB
/
1389_acm.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
52
53
54
55
56
57
58
59
60
61
62
63
#include<bits/stdc++.h>
#include<memory.h>
using namespace std;
int d[101][101];
int per[101] = {0};
int main(){
int n,m;
cin>>n>>m;
memset(d,0,sizeof(d));
for(int i=1;i<=m;i++){
int from, to;
cin>>from>>to;
d[from][to] = 1;
d[to][from] = 1;
}
for(int k=1;k<=n;k++){
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(i!=j){
if(d[i][k]>0 && d[k][j]>0 && (d[i][j] == 0 || d[i][j] > d[i][k] + d[k][j])){
d[i][j] = d[i][k] + d[k][j];
}
}
}
}
}
////
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
per[i] += d[i][j];
}
}
int min = 1000000000;
int index = 101;
for(int i=n;i>=1;i--){
if(per[i] <= min){
min = per[i];
index = i;
}
}
cout<<index<<'\n';
////
return 0;
}