158542025-03-05 02:30:15rennParti (75 pont)cpp17Accepted 75/7528ms3164 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;
    if(n < 3)
    {
        cout << "0\n";
        return 0;
    }

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

                c->next = c->next->next;
                torles = true;
                continue;
            }

            c = c->next;
        }
    }
    
    c = tagok[0].next;
    cout << n << "\n";
    while(c != NULL)
    {
        cout << c->index << " ";
        c = c->next;
    }
    cout << "\n";
}
SubtaskSumTestVerdictTimeMemory
base75/75
1Accepted0/01ms316 KiB
2Accepted0/014ms1840 KiB
3Accepted3/31ms316 KiB
4Accepted3/31ms316 KiB
5Accepted3/31ms316 KiB
6Accepted3/31ms316 KiB
7Accepted3/31ms316 KiB
8Accepted4/41ms316 KiB
9Accepted4/41ms316 KiB
10Accepted4/42ms316 KiB
11Accepted4/41ms316 KiB
12Accepted4/42ms556 KiB
13Accepted4/42ms316 KiB
14Accepted4/43ms512 KiB
15Accepted4/414ms1844 KiB
16Accepted4/417ms2056 KiB
17Accepted4/419ms2336 KiB
18Accepted4/421ms2784 KiB
19Accepted4/426ms2884 KiB
20Accepted4/428ms3160 KiB
21Accepted4/428ms3164 KiB
22Accepted4/41ms380 KiB