158552025-03-05 02:47:16rennParti (75 pont)cpp17Accepted 75/7528ms3380 KiB
#include <bits/stdc++.h>
using namespace std;
#define W while
struct Tag {int j, x, y;Tag *f = NULL;};

int main(){cin.tie(0);ios::sync_with_stdio(0);int n;cin >> n;int b[n+1] = {0};Tag t[n+1];Tag *c;for(int i = 1; i <= n; i++) {t[i].j = i;cin >> t[i].x >> t[i].y;b[t[i].x]++;b[t[i].y]++;t[i].f = t+i+1;}t[0].f = t+1;t[n].f = NULL;bool d = 1;W(d){d = 0;c = &t[0];W(c->f != NULL){if(b[c->f->j] < 2){n--;b[c->f->x]--;b[c->f->y]--;b[c->f->j] = -1;c->f = c->f->f;d = 1;continue;} c = c->f;}}c = t[0].f;cout << n << "\n";W(c != NULL) {cout << c->j << " ";c = c->f;}cout << "\n";}
SubtaskSumTestVerdictTimeMemory
base75/75
1Accepted0/01ms316 KiB
2Accepted0/014ms1848 KiB
3Accepted3/31ms316 KiB
4Accepted3/31ms316 KiB
5Accepted3/31ms316 KiB
6Accepted3/31ms316 KiB
7Accepted3/31ms556 KiB
8Accepted4/41ms316 KiB
9Accepted4/41ms448 KiB
10Accepted4/41ms316 KiB
11Accepted4/41ms316 KiB
12Accepted4/41ms316 KiB
13Accepted4/42ms316 KiB
14Accepted4/42ms316 KiB
15Accepted4/414ms1788 KiB
16Accepted4/417ms2056 KiB
17Accepted4/420ms2340 KiB
18Accepted4/421ms2756 KiB
19Accepted4/425ms2868 KiB
20Accepted4/428ms3380 KiB
21Accepted4/428ms3156 KiB
22Accepted4/41ms316 KiB