52612023-04-24 13:04:47anonDinókcpp17Partially correct 0/100136ms35240 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 += 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
1Partially correct3ms1688 KiB
2Accepted3ms1848 KiB
3Accepted8ms3412 KiB
subtask20/5
4Wrong answer129ms33248 KiB
5Wrong answer64ms23996 KiB
6Wrong answer35ms18736 KiB
subtask30/15
7Wrong answer3ms2892 KiB
8Accepted3ms3096 KiB
9Wrong answer2ms3212 KiB
10Partially correct3ms3332 KiB
11Partially correct3ms3444 KiB
12Wrong answer2ms3536 KiB
subtask40/10
13Wrong answer3ms3660 KiB
14Partially correct2ms3744 KiB
15Accepted3ms3988 KiB
16Accepted2ms4072 KiB
17Wrong answer2ms4072 KiB
subtask50/35
18Wrong answer2ms4076 KiB
19Wrong answer3ms4416 KiB
20Wrong answer101ms25892 KiB
21Wrong answer101ms25828 KiB
22Wrong answer3ms4196 KiB
23Accepted3ms4280 KiB
24Accepted101ms25948 KiB
subtask60/35
25Wrong answer123ms32188 KiB
26Wrong answer118ms32436 KiB
27Wrong answer119ms32228 KiB
28Wrong answer119ms32272 KiB
29Accepted114ms30232 KiB
30Wrong answer119ms31968 KiB
31Wrong answer120ms32212 KiB
32Accepted112ms30232 KiB
33Accepted103ms28016 KiB
34Wrong answer116ms33008 KiB
35Accepted136ms35240 KiB