101382024-03-28 00:03:59111Turista járatokcpp17Wrong answer 10/100164ms60080 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);
	sort(ans.begin(),ans.end());
	cout<<ans.size()<<'\n';
	for(int i:ans){
		cout<<i<<' ';
	}
	cout<<'\n';
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1824 KiB
2Accepted9ms4768 KiB
subtask20/10
3Accepted3ms2272 KiB
4Accepted3ms2444 KiB
5Accepted3ms2824 KiB
6Wrong answer3ms2788 KiB
7Wrong answer3ms3160 KiB
subtask310/10
8Accepted3ms3136 KiB
9Accepted3ms3208 KiB
10Accepted3ms3456 KiB
11Accepted3ms3776 KiB
12Accepted4ms4552 KiB
subtask40/10
13Accepted7ms5504 KiB
14Accepted3ms3744 KiB
15Accepted3ms3996 KiB
16Accepted4ms4464 KiB
17Wrong answer164ms58864 KiB
18Wrong answer48ms15760 KiB
19Wrong answer61ms19716 KiB
20Wrong answer46ms16156 KiB
subtask50/10
21Accepted9ms6808 KiB
22Wrong answer3ms4844 KiB
23Accepted3ms4808 KiB
24Wrong answer3ms4820 KiB
25Wrong answer90ms35872 KiB
26Wrong answer8ms6876 KiB
27Wrong answer8ms7036 KiB
subtask60/60
28Wrong answer3ms5212 KiB
29Accepted3ms5228 KiB
30Accepted4ms5484 KiB
31Accepted4ms5832 KiB
32Wrong answer4ms5980 KiB
33Accepted6ms6152 KiB
34Accepted8ms7232 KiB
35Accepted9ms7508 KiB
36Accepted9ms7444 KiB
37Wrong answer164ms60080 KiB
38Wrong answer48ms17028 KiB
39Wrong answer46ms16900 KiB
40Wrong answer46ms16904 KiB
41Wrong answer46ms16904 KiB
42Wrong answer48ms17032 KiB
43Wrong answer48ms16900 KiB
44Wrong answer46ms16900 KiB
45Wrong answer64ms20672 KiB
46Wrong answer46ms16976 KiB
47Wrong answer48ms16900 KiB
48Wrong answer46ms16952 KiB
49Wrong answer46ms16936 KiB
50Wrong answer46ms16900 KiB