-
Notifications
You must be signed in to change notification settings - Fork 0
/
BOJ_2458번.cpp
65 lines (48 loc) · 1.08 KB
/
BOJ_2458번.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
58
59
60
61
62
63
64
65
//키 순서 2458번
#include<iostream>
using namespace std;
#define MAX_SIZE 501
#define INF 987654321
int relation[MAX_SIZE][MAX_SIZE];
int up_cnt[MAX_SIZE]; //나 보다 키 큰 학생 수
int down_cnt[MAX_SIZE]; //나 보다 키 작은 학생 수
int main(void) {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m, a, b;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
relation[i][j] = INF;
}
}
for (int i = 0; i < m; i++) {
cin >> a >> b;
relation[a][b] = 1;
}
for (int k = 1; k <= n; k++) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (i == j || i == k || j == k) continue;
if (relation[i][j] > relation[i][k] + relation[k][j]) {
relation[i][j] = relation[i][k] + relation[k][j];
}
}
}
}
int ret = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (i == j) continue;
if (relation[i][j] != INF) {
up_cnt[i]++;
down_cnt[j]++;
}
}
}
for (int i = 1; i <= n; i++) {
if (up_cnt[i] + down_cnt[i] == n - 1) ret++;
}
cout << ret;
return 0;
}