-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path266.cpp
More file actions
50 lines (47 loc) · 787 Bytes
/
Copy path266.cpp
File metadata and controls
50 lines (47 loc) · 787 Bytes
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
#include <iostream>
using namespace std;
bool fl[101][101];
int main() {
int n, m;
while (cin >> n >> m) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
for (int k = 0; k < n; k++) {
fl[i][j] = 0;
}
}
}
for (int i = 0; i < m; i++) {
int x, y;
cin >> x >> y;
x--; y--;
fl[x][y] = 1;
}
for (int k = 0; k < n; k++) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (fl[i][k] && fl[k][j]) {
fl[i][j] = 1;
}
}
}
}
int ans = 0;
for (int i = 0; i < n; i++) {
int sum = 0;
for (int j = 0; j < n; j++) {
if (i == j) {
continue;
}
if (fl[i][j] || fl[j][i]) {
sum++;
}
}
if (sum == n - 1) {
ans++;
}
}
cout << ans << endl;
}
return 0;
}