14212022-09-09 19:35:51Szin AttilaDinókcpp14Accepted 100/100280ms27508 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;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1828 KiB
2Accepted2ms2056 KiB
3Accepted4ms3212 KiB
subtask25/5
4Accepted203ms23528 KiB
5Accepted180ms22720 KiB
6Accepted230ms22540 KiB
subtask315/15
7Accepted2ms3140 KiB
8Accepted2ms3236 KiB
9Accepted2ms3216 KiB
10Accepted2ms3440 KiB
11Accepted2ms3568 KiB
12Accepted2ms3552 KiB
subtask410/10
13Accepted2ms3692 KiB
14Accepted2ms3788 KiB
15Accepted2ms3992 KiB
16Accepted2ms4080 KiB
17Accepted2ms4200 KiB
subtask535/35
18Accepted2ms4208 KiB
19Accepted3ms4272 KiB
20Accepted222ms27228 KiB
21Accepted259ms27208 KiB
22Accepted2ms4424 KiB
23Accepted3ms4736 KiB
24Accepted67ms27508 KiB
subtask635/35
25Accepted263ms25332 KiB
26Accepted210ms25192 KiB
27Accepted206ms25340 KiB
28Accepted243ms25292 KiB
29Accepted68ms26208 KiB
30Accepted211ms25748 KiB
31Accepted209ms25452 KiB
32Accepted68ms26544 KiB
33Accepted71ms27232 KiB
34Accepted280ms25872 KiB
35Accepted70ms25300 KiB