-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboj1058.cpp
More file actions
45 lines (39 loc) · 1.06 KB
/
boj1058.cpp
File metadata and controls
45 lines (39 loc) · 1.06 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
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
using pii = pair<int, int>;
int n, ans;
int friendGraph[51][51];
int dist[51][51];
int main() {
cin >> n;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
dist[i][j] = INF;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
for (int j = 0; j < s.size(); j++) {
if (s[j] == 'Y') friendGraph[i][j] = 1, dist[i][j] = 1;
else friendGraph[i][j] = 0;
}
}
for (int k = 0; k < n; k++) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (dist[i][j] > dist[i][k] + dist[k][j]) {
dist[i][j] = dist[i][k] + dist[k][j];
}
}
}
}
for (int i = 0; i < n; i++) {
int cnt = 0;
for (int j = 0; j < n; j++) {
if (i == j) continue;
if (dist[i][j] <= 2) cnt++;
}
ans = max(ans, cnt);
}
cout << ans << '\n';
}