52632023-04-24 16:44:21anonDinókcpp17Wrong answer 0/100136ms36576 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, 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<ll> w(N + 1);

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

    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 = 0;

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

        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]])
                    continue;

                sames.push_back(nodes[sames[si]].sames[i]);
                w[nodes[sames[si]].sames[i]]++;
            }

            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;

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

    for(i = 1; i <= N; i++)
    {
        if(w[i] != 1)
        {
            cout << "NEM" << endl;
            return 0;
        }
    }

    cout << "IGEN" << endl;

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

    return 0;
}

SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1812 KiB
2Accepted3ms2000 KiB
3Accepted8ms3568 KiB
subtask20/5
4Wrong answer136ms34828 KiB
5Wrong answer70ms25160 KiB
6Wrong answer39ms20132 KiB
subtask30/15
7Accepted3ms2676 KiB
8Accepted3ms2916 KiB
9Wrong answer3ms2904 KiB
10Partially correct3ms3176 KiB
11Partially correct3ms3336 KiB
12Wrong answer3ms3504 KiB
subtask40/10
13Wrong answer3ms3712 KiB
14Partially correct3ms3832 KiB
15Accepted3ms3772 KiB
16Accepted3ms3888 KiB
17Wrong answer3ms3772 KiB
subtask50/35
18Wrong answer3ms3776 KiB
19Wrong answer3ms3844 KiB
20Wrong answer101ms27348 KiB
21Wrong answer101ms27560 KiB
22Wrong answer3ms4208 KiB
23Accepted3ms4308 KiB
24Accepted101ms27516 KiB
subtask60/35
25Wrong answer119ms33796 KiB
26Wrong answer123ms33920 KiB
27Wrong answer118ms33976 KiB
28Wrong answer115ms33848 KiB
29Accepted112ms31868 KiB
30Wrong answer116ms33636 KiB
31Wrong answer123ms33828 KiB
32Accepted111ms31872 KiB
33Accepted104ms29480 KiB
34Wrong answer115ms34164 KiB
35Accepted123ms36576 KiB