-
Notifications
You must be signed in to change notification settings - Fork 0
/
P1058.cpp
57 lines (45 loc) · 1.05 KB
/
P1058.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
#include <iostream>
#define INF 987654321
using namespace std;
int N;
int graph[51][51] = {};
void f() {
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
for (int k = 0; k < N; k++) {
if (graph[i][j] > graph[i][k] + graph[k][j]) {
graph[i][j] = graph[i][k] + graph[k][j];
}
}
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> N;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
char c;
cin >> c;
if (i == j) graph[i][j] = 0;
else if (c == 'Y') graph[i][j] = 1;
else graph[i][j] = INF;
}
}
f();
int result = 0;
for (int i = 0; i < N; i++) {
int ans = 0;
for (int j = 0; j < N; j++) {
if (i == j) continue;
if (graph[i][j] <= 2) {
ans++;
}
}
result = max(result, ans);
}
cout << result;
return 0;
}