158502025-03-05 01:53:33rennParti (75 pont)cpp17Wrong answer 72/7535ms4096 KiB
#include <bits/stdc++.h>
using namespace std;

struct Tag {
    int index;
    int bal, jobb;
    Tag *next = NULL;
};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int n;
    cin >> n;
    int befok[n+1] = {0};

    Tag *a = new Tag();
    Tag *b = a;
    
    for(int i = 0; i < n; i++)
    {
        Tag *c = new Tag();
        c->index = i+1;
        cin >> c->bal >> c->jobb;
        befok[c->bal]++;
        befok[c->jobb]++;
        
        b->next = c;
        b = c;
    }
    
    bool torles = true;
    while(torles)
    {
        torles = false;
        Tag *c = a;
        while(c->next != NULL)
        {
            if(befok[c->next->index] < 2)
            {
                n--;
                Tag *t = c->next;
                befok[t->bal]--;
                befok[t->jobb]--;
                c->next = t->next;
                befok[t->index] = -1;
                delete t;
                torles = true;
                continue;
            }

            c = c->next;
        }
    }
    
    b = a;
    a = a->next;
    delete b;

    cout << n << "\n";
    while(a != NULL)
    {
        cout << a->index << " ";
        a = a->next;
    }
}
SubtaskSumTestVerdictTimeMemory
base72/75
1Accepted0/01ms508 KiB
2Accepted0/017ms2100 KiB
3Accepted3/31ms316 KiB
4Accepted3/31ms316 KiB
5Wrong answer0/31ms316 KiB
6Accepted3/31ms316 KiB
7Accepted3/31ms316 KiB
8Accepted4/41ms500 KiB
9Accepted4/41ms512 KiB
10Accepted4/42ms440 KiB
11Accepted4/41ms448 KiB
12Accepted4/41ms316 KiB
13Accepted4/42ms316 KiB
14Accepted4/42ms568 KiB
15Accepted4/417ms2096 KiB
16Accepted4/420ms2544 KiB
17Accepted4/425ms3028 KiB
18Accepted4/428ms3212 KiB
19Accepted4/432ms3640 KiB
20Accepted4/434ms4096 KiB
21Accepted4/435ms4044 KiB
22Accepted4/41ms316 KiB