1421 | 2022-09-09 19:35:51 | Szin Attila | Dinók | cpp14 | Accepted 100/100 | 280ms | 27508 KiB |
#include <bits/stdc++.h>
using namespace std;
#define InTheNameOfGod ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
using ll = long long;
const int maxN = 2e5 + 5;
const int MOD = 1e9 + 7;
vector<vector<int> > g;
vector<int> tav, befok;
int main() {
#pragma region
#ifndef ONLINE_JUDGE
freopen("../input.txt", "r", stdin);
freopen("../output.txt", "w", stdout);
#endif
InTheNameOfGod;
#pragma endregion
int n,m;
cin >> n >> m;
g.resize(2*n+1);
befok.resize(2*n+1, 0);
tav.resize(2*n+1, -1);
for(int i = 0; i < n; i++) {
g[i*2].push_back(i*2+1);
befok[i*2+1]++;
}
for(int i = 0; i < m; i++) {
int x,y,z;
cin >> z >> x >> y;
x--;y--;z--;
if(z) {
g[x*2+1].push_back(y*2);
befok[y*2]++;
}
else {
g[x*2].push_back(y*2+1);
g[y*2].push_back(x*2+1);
befok[y*2+1]++;
befok[x*2+1]++;
}
}
queue<int> sor;
for(int i = 0; i < 2*n; i++) {
if(!befok[i]) sor.push(i);
}
int timer = 1, cnt = 0;
while(!sor.empty()) {
int cur = sor.front();
sor.pop();
cnt++;
tav[cur] = timer++;
for(int sz : g[cur]) {
if(--befok[sz] == 0) {
sor.push(sz);
}
}
}
if(cnt != 2*n) cout << "NEM\n";
else {
cout << "IGEN\n";
for(int i = 0; i < 2*n; i+=2) {
cout << tav[i] << ' ' << tav[i+1] << endl;
}
}
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1828 KiB | ||||
2 | Accepted | 2ms | 2056 KiB | ||||
3 | Accepted | 4ms | 3212 KiB | ||||
subtask2 | 5/5 | ||||||
4 | Accepted | 203ms | 23528 KiB | ||||
5 | Accepted | 180ms | 22720 KiB | ||||
6 | Accepted | 230ms | 22540 KiB | ||||
subtask3 | 15/15 | ||||||
7 | Accepted | 2ms | 3140 KiB | ||||
8 | Accepted | 2ms | 3236 KiB | ||||
9 | Accepted | 2ms | 3216 KiB | ||||
10 | Accepted | 2ms | 3440 KiB | ||||
11 | Accepted | 2ms | 3568 KiB | ||||
12 | Accepted | 2ms | 3552 KiB | ||||
subtask4 | 10/10 | ||||||
13 | Accepted | 2ms | 3692 KiB | ||||
14 | Accepted | 2ms | 3788 KiB | ||||
15 | Accepted | 2ms | 3992 KiB | ||||
16 | Accepted | 2ms | 4080 KiB | ||||
17 | Accepted | 2ms | 4200 KiB | ||||
subtask5 | 35/35 | ||||||
18 | Accepted | 2ms | 4208 KiB | ||||
19 | Accepted | 3ms | 4272 KiB | ||||
20 | Accepted | 222ms | 27228 KiB | ||||
21 | Accepted | 259ms | 27208 KiB | ||||
22 | Accepted | 2ms | 4424 KiB | ||||
23 | Accepted | 3ms | 4736 KiB | ||||
24 | Accepted | 67ms | 27508 KiB | ||||
subtask6 | 35/35 | ||||||
25 | Accepted | 263ms | 25332 KiB | ||||
26 | Accepted | 210ms | 25192 KiB | ||||
27 | Accepted | 206ms | 25340 KiB | ||||
28 | Accepted | 243ms | 25292 KiB | ||||
29 | Accepted | 68ms | 26208 KiB | ||||
30 | Accepted | 211ms | 25748 KiB | ||||
31 | Accepted | 209ms | 25452 KiB | ||||
32 | Accepted | 68ms | 26544 KiB | ||||
33 | Accepted | 71ms | 27232 KiB | ||||
34 | Accepted | 280ms | 25872 KiB | ||||
35 | Accepted | 70ms | 25300 KiB |