134792025-01-08 08:21:40RRoliElágazás nélküli úton levő települések (50 pont)cpp17Wrong answer 4/5039ms32000 KiB
#include <bits/stdc++.h>
using namespace std;

int n, m, fok[10001];
bool szom[10001][10001];

int main() {
	cin >> n >> m;
	for(int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		szom[a][b] = true;
		szom[b][a] = true;
		fok[a]++;
		fok[b]++;
	}

	int sor[10001], e = 0, u = 0, kezd = 0;
	bool L[10001], tovabb[10001];

	for(int i = 1; i <= n; i++) {
		if(fok[i] == 1) {
			sor[u] = i;
			u++;
			L[i] = true;
			kezd++;
		} else {
			L[i] = false;
		}
		tovabb[i] = true;
	}

	while(e <= u) {
		if(tovabb[sor[e]]) {
			for(int i = 1; i <= n; i++) {
				if(szom[sor[e]][i] && !L[i]) {
					sor[u] = i;
					L[i] = true;
					u++;
					if(fok[i] != 2) tovabb[i] = false; 
				}
			}
		}
		e++;
	}

	cout << u-kezd << '\n';
	for(int i = kezd; i < u; i++) cout << sor[i] << ' ';

	return 0;
}
SubtaskSumTestVerdictTimeMemory
base4/50
1Wrong answer0/01ms316 KiB
2Runtime error0/028ms32000 KiB
3Wrong answer0/21ms316 KiB
4Accepted2/21ms316 KiB
5Wrong answer0/21ms316 KiB
6Wrong answer0/21ms316 KiB
7Wrong answer0/21ms380 KiB
8Wrong answer0/27ms5028 KiB
9Wrong answer0/213ms10996 KiB
10Wrong answer0/221ms18640 KiB
11Accepted2/232ms28932 KiB
12Runtime error0/237ms32000 KiB
13Wrong answer0/36ms4660 KiB
14Wrong answer0/39ms10400 KiB
15Wrong answer0/319ms15916 KiB
16Wrong answer0/339ms24116 KiB
17Runtime error0/328ms32000 KiB
18Runtime error0/328ms32000 KiB
19Runtime error0/332ms32000 KiB
20Runtime error0/328ms32000 KiB
21Runtime error0/328ms32000 KiB
22Runtime error0/334ms32000 KiB