forked from ngthanhtrung23/CompetitiveProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB.cpp
More file actions
106 lines (84 loc) · 2.28 KB
/
B.cpp
File metadata and controls
106 lines (84 loc) · 2.28 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define FORD(i,a,b) for(int i=(a),_b=(b); i>=_b; i--)
#define REP(i,a) for(int i=0,_a=(a); i<_a; i++)
#define EACH(it,a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define DEBUG(x) { cout << #x << " = "; cout << (x) << endl; }
#define PR(a,n) { cout << #a << " = "; FOR(_,1,n) cout << a[_] << ' '; cout << endl; }
#define PR0(a,n) { cout << #a << " = "; REP(_,n) cout << a[_] << ' '; cout << endl; }
#define sqr(x) ((x) * (x))
#define ll long long
using namespace std;
const int MN = 200111;
int n;
struct Migrate {
int a, b, c;
int f, id;
} x[MN];
bool operator < (const Migrate& x, const Migrate& y) {
if (x.f != y.f) return x.f < y.f;
return x.id < y.id;
}
bool operator == (const Migrate& x, const Migrate& y) {
return x.id == y.id;
}
vector<int> ls[MN];
int cur[MN];
void update(Migrate& x) {
x.f = -cur[x.a] + max(cur[x.b], cur[x.c]);
// x.f = -2*cur[x.a] + cur[x.b] + cur[x.c];
}
vector<int> res;
set<Migrate> all;
bool visited[MN];
void solve() {
memset(visited, false, sizeof visited);
while (!all.empty()) {
auto u = *all.begin();
all.erase(all.begin());
int id = u.id;
res.push_back(id);
visited[id] = true;
int t[3];
t[0] = u.a;
t[1] = u.b;
t[2] = u.c;
if (cur[t[1]] == 9 || cur[t[2]] == 9) {
puts("NO");
return ;
}
cur[t[0]] -= 2;
++cur[t[1]];
++cur[t[2]];
REP(turn,3) {
for(int id : ls[t[turn]]) if (!visited[id]) {
all.erase(x[id]);
update(x[id]);
all.insert(x[id]);
}
}
}
puts("YES");
for(int id : res) printf("%d ", id); puts("");
}
int main() {
ios :: sync_with_stdio(false);
while (cin >> n) {
FOR(i,1,n) {
ls[i].clear();
cur[i] = 4;
}
all.clear();
res.clear();
FOR(i,1,4*n) {
cin >> x[i].a >> x[i].b >> x[i].c;
x[i].id = i;
update(x[i]);
all.insert(x[i]);
ls[x[i].a].push_back(i);
ls[x[i].b].push_back(i);
ls[x[i].c].push_back(i);
}
solve();
}
}