-
Notifications
You must be signed in to change notification settings - Fork 12
/
1174-commandos.cpp
65 lines (53 loc) · 1.01 KB
/
1174-commandos.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
#include <bits/stdc++.h>
#define ll long long
#define MAX 100100
using namespace std;
ll arr[110][110];
ll n;
void floyd_warshall()
{
for (int k = 0; k < n; k++) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (arr[i][j] > arr[i][k] + arr[k][j])
arr[i][j] = arr[i][k] + arr[k][j];
}
}
}
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("/home/sameer/Documents/sameer/input.sam", "r", stdin);
#endif
ios_base::sync_with_stdio(false);
ll k, m, t, cont, a, b;
cin >> t;
ll cases = t;
while (t--) {
cin >> n ;
cin >> m;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i == j)
arr[i][j] = 0;
else
arr[i][j] = INT_MAX;
}
}
for (int i = 0; i < m; i++) {
cin >> a >> b;
arr[a][b] = 1 ;
arr[b][a] = 1;
}
floyd_warshall();
ll st, dest;
cin >> st >> dest;
ll maxi = 0;
for (int i = 0; i < n; i++) {
maxi = max(arr[st][i] + arr[i][dest], maxi);
}
cout << "Case " << cases - t << ": " << maxi << endl;
}
return 0;
}