52622023-04-24 15:39:10anonDinókcpp17Wrong answer 0/100129ms35336 KiB
#include <vector>
#include <iostream>

using ll = long long;
using namespace std;

struct Node
{
    ll after;
    ll before;
    vector<ll> sames;
};

int main()
{
    ll i, a, b, c, m, pm, wc, ni, si, N, M;

    cin >> N >> M;

    vector<vector<ll>> ss(M);

    for(i = 0; i < M; i++)
    {
        cin >> a >> b >> c;
        ss[i] = vector<ll> { a, b, c };
    }

    vector<Node> nodes(N + 1);
    vector<pair<ll, ll>> ivs(N + 1);
    vector<bool> w(N + 1);

    for(i = 1; i <= N; i++)
    {
        nodes[i].after = nodes[i].before = -1;
        w[i] = false;
    }

    for(i = 0; i < M; i++)
    {
        switch(ss[i][0])
        {
            case 1:
            nodes[ss[i][1]].sames.push_back(ss[i][2]);
            nodes[ss[i][2]].sames.push_back(ss[i][1]);
            break;
            case 2:
            nodes[ss[i][1]].after = ss[i][2];
            nodes[ss[i][2]].before = ss[i][1];
            break;
            default:
            break;
        }
    }

    for(i = 1; i <= N; i++)
    {
        if(nodes[i].before == -1)
            break;
    }

    ni = i;
    pm = wc = 0;

    while(true)
    {
        w[ni] = true;

        vector<ll> sames { ni };
        si = 0;

        while(si < sames.size())
        {
            for(i = 0; i < nodes[sames[si]].sames.size(); i++)
            {
                if(!w[nodes[sames[si]].sames[i]])
                    sames.push_back(nodes[sames[si]].sames[i]);

                w[nodes[sames[si]].sames[i]] = true;
            }

            si++;
        }

        m = pm + 2 * sames.size();

        for(i = 0; i < sames.size(); i++)
            ivs[sames[i]] = make_pair(i + pm + 1, m - i);

        pm = m;
        wc += sames.size();

        if(nodes[ni].after == -1)
            break;
        else
            ni = nodes[ni].after;
    }

    if(wc != N)
        cout << "NEM" << endl;
    else
    {
        cout << "IGEN" << endl;

        for(i = 1; i <= N; i++)
            cout << ivs[i].first << ' ' << ivs[i].second << endl;
    }

    return 0;
}

SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1812 KiB
2Accepted3ms2056 KiB
3Accepted8ms3468 KiB
subtask20/5
4Wrong answer126ms33276 KiB
5Wrong answer64ms24004 KiB
6Wrong answer34ms18764 KiB
subtask30/15
7Wrong answer3ms2752 KiB
8Accepted3ms2952 KiB
9Wrong answer2ms3036 KiB
10Partially correct2ms3032 KiB
11Partially correct3ms3168 KiB
12Wrong answer3ms3388 KiB
subtask40/10
13Wrong answer3ms3624 KiB
14Partially correct3ms3832 KiB
15Accepted3ms3920 KiB
16Accepted3ms4120 KiB
17Wrong answer2ms4208 KiB
subtask50/35
18Wrong answer2ms4216 KiB
19Wrong answer3ms4276 KiB
20Wrong answer97ms25972 KiB
21Wrong answer97ms25968 KiB
22Wrong answer3ms4116 KiB
23Accepted3ms4468 KiB
24Accepted100ms26124 KiB
subtask60/35
25Wrong answer115ms32620 KiB
26Wrong answer115ms32588 KiB
27Wrong answer115ms32572 KiB
28Wrong answer114ms32568 KiB
29Accepted107ms30576 KiB
30Wrong answer112ms32432 KiB
31Wrong answer115ms32556 KiB
32Accepted108ms30588 KiB
33Accepted104ms28240 KiB
34Wrong answer119ms32996 KiB
35Accepted129ms35336 KiB