-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11463.cpp
79 lines (75 loc) · 1.31 KB
/
11463.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
11463 - Commandos
*/
#include<bits/stdc++.h>
using namespace std;
const int INF = (1e7);
int main()
{
///freopen("input.txt", "r", stdin);
///freopen("output.txt", "w", stdout);
int t,n,r,tc=0;
cin>>t;
while(t--)
{
cin>>n>>r;
int graph[n+1][n+1];
for(int i=0; i<n; i++)
{
for(int j=0; j<n; j++)
{
graph[i][j]=INF;
}
}
for(int i=0; i<r; i++)
{
int x,y;
cin>>x>>y;
graph[x][y]=1;
graph[y][x]=1;
}
for(int i=0; i<n; i++)
{
graph[i][i]=0;
}
///floyd warshall
for(int k=0; k<n; k++)
{
for(int i=0; i<n; i++)
{
for(int j=0; j<n; j++)
{
graph[i][j]=min(graph[i][j],graph[i][k]+graph[k][j]);
}
}
}
int s,e,ans=0;
cin>>s>>e;
for(int i=0; i<n; i++)
{
if(graph[s][i]!=INF && graph[i][e]!=INF)
{
ans = max(ans,graph[s][i]+graph[i][e]);
}
}
cout<<"Case "<<(++tc)<<": "<<ans<<endl;
}
return 0;
}
/*
Sample Input
2
4
3
0 1
2 1
1 3
0 3
2
1
0 1
1 0
Sample Output
Case 1: 4
Case 2: 1
*/