101372024-03-28 00:00:07111Turista járatokcpp17Wrong answer 0/100165ms60452 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]&&b){
					u[i]=1;
				}
				if(v[j]>=v[i]-1){
					continue;
				}
				if(v[j]<v[w[i]]){
					w[i]=j;
				}
				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
2Accepted9ms4560 KiB
subtask20/10
3Accepted3ms2236 KiB
4Accepted3ms2444 KiB
5Accepted3ms2664 KiB
6Wrong answer3ms2744 KiB
7Wrong answer3ms2864 KiB
subtask30/10
8Wrong answer3ms2748 KiB
9Wrong answer3ms2744 KiB
10Wrong answer3ms2880 KiB
11Wrong answer3ms3320 KiB
12Wrong answer4ms4308 KiB
subtask40/10
13Wrong answer7ms5124 KiB
14Wrong answer3ms3404 KiB
15Wrong answer3ms3656 KiB
16Wrong answer4ms3896 KiB
17Wrong answer165ms59684 KiB
18Wrong answer48ms15448 KiB
19Wrong answer64ms19096 KiB
20Wrong answer48ms15324 KiB
subtask50/10
21Wrong answer8ms6008 KiB
22Wrong answer3ms4044 KiB
23Accepted3ms4028 KiB
24Wrong answer3ms4300 KiB
25Wrong answer86ms35388 KiB
26Wrong answer8ms6324 KiB
27Wrong answer8ms6348 KiB
subtask60/60
28Wrong answer3ms4368 KiB
29Accepted3ms4384 KiB
30Wrong answer4ms4728 KiB
31Wrong answer4ms5012 KiB
32Wrong answer4ms5348 KiB
33Accepted6ms5624 KiB
34Accepted9ms6700 KiB
35Accepted9ms6848 KiB
36Accepted9ms6704 KiB
37Wrong answer165ms60452 KiB
38Wrong answer48ms16060 KiB
39Wrong answer48ms16208 KiB
40Wrong answer46ms16172 KiB
41Wrong answer48ms16180 KiB
42Wrong answer48ms16200 KiB
43Wrong answer48ms16420 KiB
44Wrong answer48ms16272 KiB
45Wrong answer64ms20344 KiB
46Wrong answer48ms16484 KiB
47Wrong answer48ms16504 KiB
48Wrong answer46ms16500 KiB
49Wrong answer46ms16504 KiB
50Wrong answer48ms16488 KiB