101362024-03-27 23:55:22111Turista járatokcpp17Wrong answer 0/100170ms61104 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N,M,K;
	cin>>N>>M>>K;
	vector<vector<pair<int,int>>>g(N+1);
	for(int i=0;i<M;i++){
		int a,b;
		cin>>a>>b;
		g[a].emplace_back(b,i<K);
		g[b].emplace_back(a,i<K);
	}
	vector<int>v(N+1),w(N+1),u(N+1);
	auto dfs=[&](auto self,int i)->void{
		w[i]=i;
		for(auto[j,b]:g[i]){
			if(v[j]){
				if(v[j]>=v[i]-1){
					continue;
				}
				if(v[j]<v[w[i]]){
					w[i]=j;
				}
				if(b){
					for(auto[k,_]:g[i]){
						u[k]=1;
					}
				}
				continue;
			}
			v[j]=v[i]+1;
			self(self,j);
			if(v[w[j]]<v[w[i]]){
				w[i]=w[j];
			}
			if(b){
				if(w[j]==i){
					u[j]=1;
				}
				else{
					for(auto[k,_]:g[w[j]]){
						if(v[k]<v[w[j]]){
							continue;
						}
						u[k]=1;
					}
				}
			}
		}
	};
	v[1]=1;
	dfs(dfs,1);
	vector<int>ans;
	auto dfs2=[&](auto self,int i,int b)->void{
		if(b){
			ans.push_back(i);
		}
		for(auto[j,_]:g[i]){
			if(v[j]!=v[i]+1){
				continue;
			}
			self(self,j,b||u[j]);
		}
	};
	dfs2(dfs2,1,0);
	sort(ans.begin(),ans.end());
	cout<<ans.size()<<'\n';
	for(int i:ans){
		cout<<i<<' ';
	}
	cout<<'\n';
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1824 KiB
2Accepted10ms4772 KiB
subtask20/10
3Accepted3ms2280 KiB
4Accepted3ms2444 KiB
5Accepted3ms2660 KiB
6Wrong answer3ms2872 KiB
7Wrong answer3ms2976 KiB
subtask30/10
8Wrong answer3ms2960 KiB
9Wrong answer3ms2952 KiB
10Wrong answer3ms3088 KiB
11Wrong answer3ms3520 KiB
12Wrong answer4ms4528 KiB
subtask40/10
13Wrong answer8ms5536 KiB
14Wrong answer3ms3800 KiB
15Wrong answer3ms4016 KiB
16Wrong answer4ms4388 KiB
17Wrong answer156ms60384 KiB
18Wrong answer46ms15912 KiB
19Wrong answer65ms19956 KiB
20Wrong answer48ms16292 KiB
subtask50/10
21Wrong answer9ms6764 KiB
22Wrong answer3ms4456 KiB
23Accepted3ms4488 KiB
24Wrong answer3ms4636 KiB
25Wrong answer93ms35760 KiB
26Wrong answer9ms6752 KiB
27Wrong answer9ms6820 KiB
subtask60/60
28Wrong answer3ms4920 KiB
29Accepted3ms4812 KiB
30Wrong answer4ms5064 KiB
31Wrong answer4ms5312 KiB
32Wrong answer4ms5556 KiB
33Accepted6ms5960 KiB
34Accepted9ms7052 KiB
35Accepted10ms7424 KiB
36Accepted9ms7384 KiB
37Wrong answer170ms61104 KiB
38Wrong answer48ms16756 KiB
39Wrong answer46ms16776 KiB
40Wrong answer46ms16772 KiB
41Wrong answer46ms16788 KiB
42Wrong answer48ms16816 KiB
43Wrong answer48ms16808 KiB
44Wrong answer48ms16796 KiB
45Wrong answer64ms20600 KiB
46Wrong answer48ms16868 KiB
47Wrong answer48ms16772 KiB
48Wrong answer48ms16756 KiB
49Wrong answer48ms17052 KiB
50Wrong answer46ms17004 KiB