132682025-01-07 11:27:38mateElágazás nélküli úton levő települések (50 pont)cpp17Wrong answer 23/5028ms1332 KiB
#include <bits/stdc++.h>
using namespace std;

vector <vector <int>> graf;
vector <bool> jart;
int cnt = 0;
vector <int> csucsok;

void dfs(int csucs, bool level){
	if(jart[csucs]){
		level = 0;
		return;
	}
	if(!level){
		return;
	}
	jart[csucs] = 1;
	if(graf[csucs].size() <= 2){
		cnt++;
		level = 1;
	}else{
		level = 0;
		return;
	}

	for(int x : graf[csucs]){
		if(jart[x]){
			continue;
		}
		dfs(x, level);
		if(level){
			csucsok.push_back(x);
		}
	}
}

int main() {
	int n,m; cin >> n >> m;
	graf.resize(n+1);
	jart.resize(n+1,0);
	for(int i = 0; i < m; i++){
		int a,b; cin >> a >> b;
		graf[a].push_back(b);
		graf[b].push_back(a);
	}
	for(int i = 1; i <= n; i++){
		if(graf[i].size() == 1 && !jart[i]){
			dfs(i,1);
		}
	}
	cout << cnt << '\n';
	sort(csucsok.begin(),csucsok.end());
	for(int i = 0; i < cnt; i++){
		cout << csucsok[i] << ' ';
	}
	
}
SubtaskSumTestVerdictTimeMemory
base23/50
1Accepted0/01ms508 KiB
2Accepted0/028ms1332 KiB
3Wrong answer0/21ms316 KiB
4Wrong answer0/21ms316 KiB
5Accepted2/21ms316 KiB
6Wrong answer0/21ms316 KiB
7Accepted2/21ms316 KiB
8Accepted2/23ms316 KiB
9Accepted2/24ms564 KiB
10Accepted2/28ms568 KiB
11Accepted2/214ms616 KiB
12Accepted2/214ms816 KiB
13Wrong answer0/32ms536 KiB
14Wrong answer0/33ms500 KiB
15Wrong answer0/34ms564 KiB
16Wrong answer0/34ms564 KiB
17Wrong answer0/312ms832 KiB
18Wrong answer0/313ms820 KiB
19Wrong answer0/316ms980 KiB
20Accepted3/327ms1288 KiB
21Accepted3/328ms1132 KiB
22Accepted3/328ms1160 KiB