52122023-04-22 18:30:48ZsofiaKeresztelyDinókcpp14Accepted 100/100165ms29736 KiB
#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > g;
vector<int> ind;
vector<int> op;
int n, last = 1;

void bfs(){
    queue<int> q;
    for (int i=1; i<=n; i++){
        if (!ind[i]){
            q.push(i);
        }
    }
    while (!q.empty()){
        int v = q.front();
        q.pop();
        op[v] = last;
        last++;
        for (int x : g[v]){
            ind[x]--;
            if (!ind[x]) q.push(x);
        }
    }
}

int main()
{
    int m;
    cin >> n >> m;
    g.resize(2*n+1);
    ind.assign(2*n+1, 0);
    op.assign(2*n+1, 0);
    while (m--){
        int t, a, b;
        cin >> t >> a >> b;
        if (t == 2){
            g[a + n].push_back(b);
            ind[b]++;
        }
        else{
            g[b].push_back(a + n);
            g[a].push_back(b + n);
            ind[a+n]++;
            ind[b+n]++;
        }
    }
    for (int i=1; i<=n; i++){
        g[i].push_back(i + n);
        ind[i+n]++;
    }
    bfs();
    for (int i=1; i<=2*n; i++){
        if (!op[i]){
            cout << "NEM";
            return 0;
        }
    }
    cout << "IGEN";
    for (int i=1; i<=n; i++){
        cout << "\n" << op[i] << " " << op[i + n];
    }
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1808 KiB
2Accepted3ms2060 KiB
3Accepted8ms3184 KiB
subtask25/5
4Accepted157ms23892 KiB
5Accepted96ms24652 KiB
6Accepted74ms25080 KiB
subtask315/15
7Accepted3ms5728 KiB
8Accepted3ms5624 KiB
9Accepted2ms5716 KiB
10Accepted2ms5744 KiB
11Accepted3ms5720 KiB
12Accepted3ms5704 KiB
subtask410/10
13Accepted3ms5792 KiB
14Accepted3ms5924 KiB
15Accepted3ms6164 KiB
16Accepted3ms6260 KiB
17Accepted2ms6376 KiB
subtask535/35
18Accepted3ms6300 KiB
19Accepted3ms6444 KiB
20Accepted148ms29536 KiB
21Accepted145ms29620 KiB
22Accepted3ms6600 KiB
23Accepted3ms6676 KiB
24Accepted122ms29736 KiB
subtask635/35
25Accepted152ms27604 KiB
26Accepted150ms27612 KiB
27Accepted164ms27696 KiB
28Accepted164ms27700 KiB
29Accepted133ms28520 KiB
30Accepted157ms28280 KiB
31Accepted165ms27996 KiB
32Accepted134ms28408 KiB
33Accepted129ms29580 KiB
34Accepted158ms28244 KiB
35Accepted128ms27340 KiB