forked from fatemehkarimi/uvaSolutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuva-10803.cpp
79 lines (58 loc) · 1.47 KB
/
uva-10803.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
//uva 10803
//Thunder Mountain
#include <iostream>
#include <iomanip>
#include <climits>
#include <vector>
#include <cmath>
using namespace std;
double distance(pair <int, int> x, pair <int, int> y);
int main(void)
{
int T = 0;
int tcounter = 0;
cin >> T;
while(T--){
++tcounter;
int n = 0;
cin >> n;
vector < pair <int, int> > coordiante(n);
for(int i = 0; i < n; ++i){
int x, y;
cin >> x >> y;
coordiante[i] = make_pair(x, y);
}
vector < vector <double> > Graph(n, vector <double> (n, INT_MAX));
for(int i = 0; i < n; ++i)
for(int j = i + 1; j < n; ++j){
double d = distance(coordiante[i], coordiante[j]);
if(d > 10)
continue;
Graph[i][j] = d;
Graph[j][i] = d;
}
for(int i = 0; i < n; ++i)
Graph[i][i] = 0;
for(int k = 0; k < n; ++k)
for(int i = 0; i < n; ++i)
for(int j = 0; j < n; ++j)
if(Graph[i][k] != INT_MAX && Graph[k][j] != INT_MAX)
Graph[i][j] = min(Graph[i][j], Graph[i][k] + Graph[k][j]);
double result = INT_MIN;
for(int i = 0; i < n; ++i)
for(int j = 0; j < n; ++j)
result = max(result, Graph[i][j]);
cout << "Case #" << tcounter << ":" << endl;
if(result == INT_MAX)
cout << "Send Kurdy" << endl;
else
cout << fixed << left << setprecision(4) << result << endl;
cout << endl;
}
return 0;
}
double distance(pair <int, int> x, pair <int, int> y)
{
return sqrt((x.first - y.first) * (x.first - y.first)
+ (x.second - y.second) * (x.second - y.second));
}