2532021-03-06 16:39:33mraronElfogáscpp14Accepted 50/5035ms13860 KiB
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cassert>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#include<functional>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<sstream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<numeric>
#include<random>
#include<chrono>
#include<bitset>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define sz(x) (int)(x).size()
#define gc getchar
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mp make_pair

#ifndef ONLINE_JUDGE
#  define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
#  define LOG(x) ((void)0)
#endif

using ll = long long;
using ull = unsigned long long ;
using ld = long double ;
using str = string;
using ordered_set=tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update>;

const double PI=acos(-1);
const ll INF = 1LL<<62;
const ll MINF = -(1LL<<62);

template<typename T> T getint() {
	T val=0;
	char c;
	
	bool neg=false;
	while((c=gc()) && !(c>='0' && c<='9')) {
		neg|=c=='-';
	}

	do {
		val=(val*10)+c-'0';
	} while((c=gc()) && (c>='0' && c<='9'));

	return val*(neg?-1:1);
}

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution<int>(0, n-1)(rng)

int n,m,u,v;
vector<pair<int, int>> adj[20001];
int dfs_low[20001], dfs_num[20001], par[20001], dfs_cnt=0;
set<int> ans;
void dfs0(int x, int pr=-1) {
	dfs_low[x]=dfs_num[x]=++dfs_cnt;

	for(auto i:adj[x]) {
		if(i.yy==pr) continue ;
		if(dfs_low[i.xx]>0) {
			dfs_low[x]=min(dfs_low[x], dfs_num[i.xx]);
		}else {
			par[i.xx]=x;
			dfs0(i.xx, i.yy);
			dfs_low[x]=min(dfs_low[x], dfs_low[i.xx]);
		}
	}
}

int st[20001];
void dfs1(int x, int pr) {
	st[x]=1;
	ans.insert(x);
	for(auto i:adj[x]) {
		if(st[i.xx] || i.xx==pr) continue ;
		dfs1(i.xx, x);
	}
}

int main() {
	IO;
	
	cin>>n>>m>>u>>v;
	
	for(int i=0;i<m;++i) {
		int a,b;
		cin>>a>>b;
		adj[a].push_back({b, i});
		adj[b].push_back({a, i});
	}
	
	dfs0(u);
	vector<int> lst;
	int akt=v;
	while(akt!=u) {
		if(dfs_num[akt]==dfs_low[akt]) break ;

		lst.push_back(akt);
		akt=par[akt];
	}
	
	akt=v;
	while(akt!=u) st[akt]=1, akt=par[akt];
	st[u]=1;
	
	ans.insert(v);
	for(auto i:lst) dfs1(i, -1);
	
	cout<<sz(ans)<<"\n";
	for(auto i:ans) cout<<i<<" ";
	cout<<"\n";
	return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/02ms2760 KiB
2Accepted0/07ms4440 KiB
3Accepted2/21ms2948 KiB
4Accepted2/22ms3000 KiB
5Accepted2/22ms3032 KiB
6Accepted2/22ms3060 KiB
7Accepted3/32ms3092 KiB
8Accepted3/32ms3112 KiB
9Accepted3/33ms3484 KiB
10Accepted3/33ms3540 KiB
11Accepted3/34ms3908 KiB
12Accepted3/34ms4444 KiB
13Accepted3/38ms4776 KiB
14Accepted3/310ms5132 KiB
15Accepted3/312ms5204 KiB
16Accepted3/320ms8400 KiB
17Accepted3/321ms9236 KiB
18Accepted3/321ms10028 KiB
19Accepted3/327ms10604 KiB
20Accepted3/335ms13860 KiB