135602025-01-08 09:52:42Leventusz09Elágazás nélküli úton levő települések (50 pont)cpp17Wrong answer 6/5028ms1332 KiB
#include <iostream>
#include <vector>

#define nMax 10000

using namespace std;

vector<int> et[nMax];  // et[0] => élek a 0. vársoból/-ba
bool zsákfalvak[nMax]; 
bool ty[nMax];         // számlált városok

vector<int> ol;

void appendZsákfalvak(int index) {
	bool zsákfalu = zsákfalvak[index];
	ty[index] = 1;

	if (zsákfalu) {
		if(!ty[et[index][0]]) appendZsákfalvak(et[index][0]);

		return;
	}

	ol.push_back(index);

	if (et[index].size() == 2) {
		if(!ty[et[index][0]]) appendZsákfalvak(et[index][0]);
		if(!ty[et[index][1]]) appendZsákfalvak(et[index][1]);
	}
}

int main() {
	int N, M;
	cin >> N >> M;

	for (int i = 0, a, b; i < M; i++) {
		cin >> a >> b;
		a--; b--;
		et[a].push_back(b);
		et[b].push_back(a);
	}

	for (int i = 0; i < N; i++) {
		if (et[i].size() != 1) continue;
		zsákfalvak[i] = 1;
		appendZsákfalvak(i);
	}

	cout << ol.size() << "\n";
	for (int& i : ol) cout << i + 1 << " ";


	return 0;
}
SubtaskSumTestVerdictTimeMemory
base6/50
1Accepted0/01ms564 KiB
2Wrong answer0/028ms1332 KiB
3Wrong answer0/21ms564 KiB
4Accepted2/21ms564 KiB
5Accepted2/21ms564 KiB
6Wrong answer0/21ms564 KiB
7Wrong answer0/21ms564 KiB
8Wrong answer0/23ms568 KiB
9Wrong answer0/24ms564 KiB
10Wrong answer0/28ms812 KiB
11Accepted2/214ms864 KiB
12Wrong answer0/214ms816 KiB
13Wrong answer0/32ms644 KiB
14Wrong answer0/34ms564 KiB
15Wrong answer0/34ms684 KiB
16Wrong answer0/34ms564 KiB
17Wrong answer0/312ms832 KiB
18Wrong answer0/313ms968 KiB
19Wrong answer0/317ms968 KiB
20Wrong answer0/328ms1300 KiB
21Wrong answer0/328ms1332 KiB
22Wrong answer0/328ms1288 KiB