-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScale.cpp
More file actions
61 lines (54 loc) · 947 Bytes
/
Copy pathScale.cpp
File metadata and controls
61 lines (54 loc) · 947 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
51
52
53
54
55
56
57
58
59
60
61
// Baekjoon(10159)
// Floyd-Warshall Algorithm
#include <iostream>
#include <array>
#include <algorithm>
using namespace std;
const int INF = 2010;
int N, M, a, b;
array<array<int, 101>, 101> dp;
void Init() {
for (int i{ 0 }; i <= N; i++) {
for (int j{ 0 }; j <= N; j++) {
dp[i][j] = INF;
}
}
}
void Fwa() {
for (int k{ 1 }; k <= N; k++) {
for (int i{ 1 }; i <= N; i++) {
for (int j{ 1 }; j <= N; j++) {
dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
}
}
}
for (int i{ 1 }; i <= N; i++) {
for (int j{ 1 }; j <= N; j++) {
if (dp[i][j] < INF) {
dp[j][i] = dp[i][j];
}
}
}
}
void count(int n) {
int answer = 0;
for (int i{ 1 }; i <= N; i++) {
if (i == n || dp[n][i] < INF)
continue;
answer++;
}
cout << answer << endl;
}
int main() {
cin >> N;
cin >> M;
Init();
for (int i{ 0 }; i < M; i++) {
cin >> a >> b;
dp[a][b] = 1;
}
Fwa();
for (int i{ 1 }; i <= N; i++) {
count(i);
}
}