-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11463.cpp
More file actions
59 lines (58 loc) · 1.28 KB
/
11463.cpp
File metadata and controls
59 lines (58 loc) · 1.28 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
#include <bits/stdc++.h>
using namespace std;
int building[105][105];
void dijsktra(int s,int n,int time[])
{
vector<int> dis(n,1e9);
vector<bool> visit(n,false);
dis[s]=0;
int ans(0);
for(int j=0; j<n; j++)
{
int minv=1e9,u=-1;
for(int i=0; i<n; i++)
{
if(dis[i]<minv&&!visit[i])
{
minv=dis[i];
u=i;
}
}
if(u==-1)
break;
visit[u]=true;
for(int i=0; i<n; i++)
{
if(!visit[i]&&building[u][i]&&dis[i]>dis[u]+building[u][i])
dis[i]=dis[u]+building[u][i];
}
}
for(int i=0;i<n;i++)
time[i]=dis[i];
}
int main()
{
int t,n,s,e,r,st[105],et[105],kase(0);
cin>>t;
while(t--)
{
cin>>n>>r;
memset(building,0,sizeof(building));
for(int i=0; i<r; i++)
{
cin>>s>>e;
building[s][e]=building[e][s]=1;
}
cin>>s>>e;
dijsktra(s,n,st);
dijsktra(e,n,et);
int ans(0);
for(int i=0;i<n;i++)
{
ans=max(ans,st[i]+et[i]);
}
cout<<"Case "<<++kase<<": ";
cout<<ans<<endl;
}
return 0;
}