forked from ngthanhtrung23/CompetitiveProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathD.cpp
More file actions
59 lines (52 loc) · 1.15 KB
/
D.cpp
File metadata and controls
59 lines (52 loc) · 1.15 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
#include <bits/stdc++.h>
using namespace std;
int n, a[222], id[222], active[222][222], deg[222];
vector <int> edge[222];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
freopen("bubble.in", "r", stdin);
freopen("bubble.out", "w", stdout);
cin >> n;
for (int i = 1; i < n; i++)
for (int j = 1; j <= i; j++)
cin >> active[i][j];
for (int i = 1; i <= n; i++)
id[i] = i;
for (int i = 1; i < n; i++)
for (int j = n - 1; j >= i; j--)
if (active[j][i])
{
edge[id[j + 1]].push_back(id[j]);
deg[id[j]]++;
swap(id[j], id[j + 1]);
}
else
{
edge[id[j]].push_back(id[j + 1]);
deg[id[j + 1]]++;
}
queue <int> q;
for (int i = 1; i <= n; i++)
if (!deg[i])
q.push(i);
for (int i = 1; i <= n; i++)
if (q.empty())
{
cout << "NO" << endl;
return 0;
}
else
{
int x = q.front();
a[x] = i;
q.pop();
for (int y : edge[x])
if (!--deg[y])
q.push(y);
}
cout << "YES" << endl;
for (int i = 1; i <= n; i++)
cout << a[i] << ' ';
}