-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCowContest266.cpp
More file actions
57 lines (53 loc) · 1.07 KB
/
CowContest266.cpp
File metadata and controls
57 lines (53 loc) · 1.07 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
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
#include <list>
using namespace std;
int n, m;
int num_to_check = 0;
int dist[1001][1001] = { 0 };
void floydWarshall() {
for (int k = 1; k <= n; k++) {
for (int i = 1; i <= n; i++) {
if (dist[i][k] == num_to_check)
for (int j = 1; j <= n; j++) {
if ((dist[i][j] != num_to_check) && (dist[i][k] == num_to_check) && (dist[k][j] == num_to_check)) {
/*
actual relaxation step is
if dist[i][j] > dist[i][k] + dist[k][j]
dist[i][j] = dist[i][k] + dist[k][j]
*/
dist[i][j] = num_to_check;
}
}
}
}
}
int main() {
while (cin >> n >> m) {
num_to_check++;
int ctr = 0;
int u;
int v;
for (int i = 0; i < m; i++) {
cin >> u >> v;
dist[u][v] = num_to_check;
}
floydWarshall();
for (int i = 1; i <= n; i++) {
bool flag = true;
for (int j = 1; j <= n; j++) {
if (i == j)
continue;
if (dist[i][j] == num_to_check || dist[j][i] == num_to_check) {
}
else {
flag = false;
break;
}
}
if (flag == true)
ctr++;
}
cout << ctr << endl;
}
return 0;
}