1421 | 2022-09-09 19:35:51 | Szin Attila | Dinók | cpp14 | Elfogadva 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;
}
Részfeladat | Összpont | Teszt | Verdikt | Idő | Memória | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Elfogadva | 3ms | 1828 KiB | ||||
2 | Elfogadva | 2ms | 2056 KiB | ||||
3 | Elfogadva | 4ms | 3212 KiB | ||||
subtask2 | 5/5 | ||||||
4 | Elfogadva | 203ms | 23528 KiB | ||||
5 | Elfogadva | 180ms | 22720 KiB | ||||
6 | Elfogadva | 230ms | 22540 KiB | ||||
subtask3 | 15/15 | ||||||
7 | Elfogadva | 2ms | 3140 KiB | ||||
8 | Elfogadva | 2ms | 3236 KiB | ||||
9 | Elfogadva | 2ms | 3216 KiB | ||||
10 | Elfogadva | 2ms | 3440 KiB | ||||
11 | Elfogadva | 2ms | 3568 KiB | ||||
12 | Elfogadva | 2ms | 3552 KiB | ||||
subtask4 | 10/10 | ||||||
13 | Elfogadva | 2ms | 3692 KiB | ||||
14 | Elfogadva | 2ms | 3788 KiB | ||||
15 | Elfogadva | 2ms | 3992 KiB | ||||
16 | Elfogadva | 2ms | 4080 KiB | ||||
17 | Elfogadva | 2ms | 4200 KiB | ||||
subtask5 | 35/35 | ||||||
18 | Elfogadva | 2ms | 4208 KiB | ||||
19 | Elfogadva | 3ms | 4272 KiB | ||||
20 | Elfogadva | 222ms | 27228 KiB | ||||
21 | Elfogadva | 259ms | 27208 KiB | ||||
22 | Elfogadva | 2ms | 4424 KiB | ||||
23 | Elfogadva | 3ms | 4736 KiB | ||||
24 | Elfogadva | 67ms | 27508 KiB | ||||
subtask6 | 35/35 | ||||||
25 | Elfogadva | 263ms | 25332 KiB | ||||
26 | Elfogadva | 210ms | 25192 KiB | ||||
27 | Elfogadva | 206ms | 25340 KiB | ||||
28 | Elfogadva | 243ms | 25292 KiB | ||||
29 | Elfogadva | 68ms | 26208 KiB | ||||
30 | Elfogadva | 211ms | 25748 KiB | ||||
31 | Elfogadva | 209ms | 25452 KiB | ||||
32 | Elfogadva | 68ms | 26544 KiB | ||||
33 | Elfogadva | 71ms | 27232 KiB | ||||
34 | Elfogadva | 280ms | 25872 KiB | ||||
35 | Elfogadva | 70ms | 25300 KiB |