-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1389.cpp
More file actions
60 lines (59 loc) · 1.16 KB
/
1389.cpp
File metadata and controls
60 lines (59 loc) · 1.16 KB
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
#include<iostream>
#include<vector>
#include<algorithm>
#define INF 987654321
using namespace std;
int dist[101][101];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,m,a,b,c;
cin>>n>>m;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
{
if(i==j)
dist[i][j]=0;
else
dist[i][j]=INF;
}
for(int i=0;i<m;i++)
{
cin>>a>>b;
dist[a][b]=dist[b][a]=1;
}
for(int k=1;k<=n;k++)
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
{
if(dist[i][j]>dist[i][k]+dist[k][j])
{
dist[i][j]=dist[i][k]+dist[k][j];
}
}
int sum[101];
int minsum=INF;
for(int i=1;i<=n;i++)
{
int ans=0;
for(int j=1;j<=n;j++)
{
if(dist[i][j]!=INF)
{
ans+=dist[i][j];
}
}
minsum=min(ans,minsum);
sum[i]=ans;
}
vector<int> arc;
for(int i=1;i<=n;i++)
{
if(sum[i]==minsum)
{
cout<<i;
return 0;
}
}
}