-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path6156.cpp
More file actions
64 lines (60 loc) · 1.18 KB
/
6156.cpp
File metadata and controls
64 lines (60 loc) · 1.18 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
58
59
60
61
62
63
64
// 6156. Cow Contest
// 2019.05.21
// 플로이드 와샬 알고리즘
#include<iostream>
using namespace std;
int d[101][101];
int main()
{
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++)
{
int from, to;
cin >> from >> to;
// 대소방향을 나타내기 위해 1과 -1로 저장
d[from][to] = 1;
d[to][from] = -1;
}
// 1>2, 2>3 일때 1>3인 경우들을 찾는 과정
for (int i = 1; i <= n; i++)
{
for (int from = 1; from <= n; from++)
{
// from 과 i의 대소관계가 없는 상태면 무시
if (d[from][i] == 0)
{
continue;
}
for (int to = 1; to <= n; to++)
{
// from과 i의 대소 관계 방향과 i와 to의 대소 관계 방향이 같다면
// from과 to의 대소관계도 같게 해줌.
if (d[from][i] == d[i][to])
{
d[from][to] = d[from][i];
}
}
}
}
int answer = 0;
for (int i = 1; i <= n; i++)
{
int sum = 0;
for (int j = 1; j <= n; j++)
{
// 대소 관계가 있을 때 sum을 증가
if (d[i][j] != 0 && (i != j))
{
sum++;
}
}
// 대소 관계가 모두 있다면 순위를 매길수 있는 선수
if (sum == (n - 1))
{
answer++;
}
}
cout << answer << endl;
return 0;
}