135052025-01-08 08:55:37RRoliElágazás nélküli úton levő települések (50 pont)cpp17Wrong answer 31/5028ms1332 KiB
#include <bits/stdc++.h>
using namespace std;

int n, m, fok[10001], sor[10001];

int aux[10001];
void msort(int e1, int u2) {
	int u1 = (e1+u2)/2, e2 = u1+1;
	if(e1 != u1) msort(e1, u1);
	if(e2 != u2) msort(e2, u2);
	int l = e1, r = e2, p = e1;
	while(p <= u2) {
		if(r > u2 || (sor[l] <= sor[r] && l <= u1)) {
			aux[p] = sor[l];
			l++;
		} else {
			aux[p] = sor[r];
			r++;
		}
		p++;
	}
	for(int i = e1; i <= u2; i++) sor[i] = aux[i];
}

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

	int 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 && u != 0) {
		if(tovabb[sor[e]]) {
			for(auto i : szom[sor[e]]) {
				if(!L[i]) {
					sor[u] = i;
					L[i] = true;
					u++;
					if(fok[i] != 2) tovabb[i] = false; 
				}
			}
		}
		e++;
	}

	cout << u-kezd << '\n';
	if(u-kezd > 1) msort(kezd, u-1);
	for(int i = kezd; i < u; i++) cout << sor[i] << ' ';

	return 0;
}
SubtaskSumTestVerdictTimeMemory
base31/50
1Accepted0/01ms316 KiB
2Accepted0/028ms1332 KiB
3Wrong answer0/21ms328 KiB
4Accepted2/21ms316 KiB
5Accepted2/21ms316 KiB
6Wrong answer0/21ms316 KiB
7Accepted2/21ms316 KiB
8Accepted2/23ms500 KiB
9Accepted2/24ms580 KiB
10Accepted2/28ms608 KiB
11Accepted2/214ms772 KiB
12Accepted2/214ms808 KiB
13Accepted3/32ms316 KiB
14Wrong answer0/34ms484 KiB
15Wrong answer0/34ms604 KiB
16Wrong answer0/34ms564 KiB
17Wrong answer0/312ms748 KiB
18Wrong answer0/313ms896 KiB
19Accepted3/316ms1044 KiB
20Accepted3/328ms1312 KiB
21Accepted3/328ms1292 KiB
22Accepted3/328ms1176 KiB