101392024-03-28 00:19:22111Turista járatokcpp17Time limit exceeded 10/100349ms31552 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){
					if(w[j]==i||w[j]==j){
						u[j]=1;
					}
					else{
						for(auto[k,_]:g[w[j]]){
							if(v[k]<v[w[j]]){
								continue;
							}
							u[k]=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||w[j]==j){
					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);
	if(1){
		vector<int>v(N+1),u(N+1);
		auto bt=[&](auto self,int i,int b)->void{
			if(v[i]){
				return;
			}
			if(b){
				u[i]=1;
			}
			v[i]=1;
			for(auto[j,x]:g[i]){
				self(self,j,b||x);
			}
			v[i]=0;
		};
		bt(bt,1,0);
		vector<int>ans1;
		for(int i=1;i<=N;i++){
			if(u[i]){
				ans1.push_back(i);
			}
		}
		if(ans1.size()!=ans.size()){
			ans=ans1;
		}
	}
	cout<<ans.size()<<'\n';
	for(int i:ans){
		cout<<i<<' ';
	}
	cout<<'\n';
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1828 KiB
2Time limit exceeded300ms2796 KiB
subtask20/10
3Accepted3ms2236 KiB
4Accepted3ms2332 KiB
5Accepted3ms2548 KiB
6Accepted3ms2760 KiB
7Time limit exceeded300ms2832 KiB
subtask310/10
8Accepted3ms2980 KiB
9Accepted2ms3052 KiB
10Accepted3ms3192 KiB
11Accepted3ms3504 KiB
12Accepted4ms4464 KiB
subtask40/10
13Accepted8ms5504 KiB
14Accepted4ms3276 KiB
15Time limit exceeded273ms3504 KiB
16Time limit exceeded273ms3872 KiB
17Time limit exceeded275ms30756 KiB
18Time limit exceeded349ms9268 KiB
19Time limit exceeded254ms11468 KiB
20Time limit exceeded335ms9696 KiB
subtask50/10
21Time limit exceeded273ms4580 KiB
22Accepted159ms3980 KiB
23Time limit exceeded331ms3896 KiB
24Time limit exceeded261ms4048 KiB
25Time limit exceeded337ms19240 KiB
26Time limit exceeded284ms4604 KiB
27Time limit exceeded273ms4676 KiB
subtask60/60
28Time limit exceeded277ms4456 KiB
29Time limit exceeded349ms4528 KiB
30Time limit exceeded344ms3720 KiB
31Time limit exceeded261ms4024 KiB
32Time limit exceeded277ms4184 KiB
33Time limit exceeded264ms4236 KiB
34Time limit exceeded284ms4948 KiB
35Time limit exceeded256ms5116 KiB
36Time limit exceeded273ms5000 KiB
37Time limit exceeded266ms31552 KiB
38Time limit exceeded286ms10148 KiB
39Time limit exceeded270ms10328 KiB
40Time limit exceeded266ms10144 KiB
41Time limit exceeded257ms10164 KiB
42Time limit exceeded254ms10096 KiB
43Time limit exceeded261ms10164 KiB
44Time limit exceeded273ms10076 KiB
45Time limit exceeded254ms12052 KiB
46Time limit exceeded277ms10148 KiB
47Time limit exceeded286ms10132 KiB
48Time limit exceeded277ms10172 KiB
49Time limit exceeded277ms10320 KiB
50Time limit exceeded266ms10108 KiB