Submission #588168

# Submission time Handle Problem Language Result Execution time Memory
588168 2022-07-02T18:31:23 Z Blagojce Potemkin cycle (CEOI15_indcyc) C++11
10 / 100
43 ms 1284 KB
#include <bits/stdc++.h>
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define st first
#define nd second
#define pb push_back
#define pq priority_queue
#define all(x) begin(x), end(x)

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

const int mxn = 1003;

int n, m;
vector<int> g[mxn];		
		
int dep[mxn];	
int state[mxn];
int D[mxn];
int L[mxn];

int restore[mxn];
int parent[mxn];

void dfs(int u){
	state[u] = 1;
	
	fr(i, 0, (int)g[u].size()){
		auto e = g[u][i];
		restore[i] = L[e];
		
		if(state[e] == 1 && e != parent[u]){
			L[e] = min(L[e], dep[u]);
		}
	}
	for(auto e : g[u]){
		if(state[e] == 2) continue;
		if(state[e] == 0){
			dep[e] = dep[u] + 1;
			parent[e] = u;
			dfs(e);
		}
		else if(e != parent[u]){
			D[u] = max(D[u], dep[e]);	
		}
	}
	
	for(auto e : g[u]){
		if(state[e] != 1 || dep[u] - dep[e] < 3) continue;
		
		int x = u;
		bool ok = true;
		while(dep[x] >= dep[e]){
			if(x == u || x == e){
				if(L[x] < dep[u] || dep[e] < D[x]){
					ok = false;
					break;
				}
			}
			else{
				if(L[x] <= dep[u] || dep[e] <= D[x]){
					ok = false;
					break;
				}
			}
			
			
			x = parent[x];
		}
		if(ok){
			x = u;
			vector<int> sol;
			while(dep[x] >= dep[e]){
				sol.pb(x);
				x = parent[x];
			}
			reverse(all(sol));
			for(auto u : sol) cout<<u+1<<' ';
			cout<<endl;
			exit(0);
		}
	}
	fr(i, 0, (int)g[u].size()){
		auto e = g[u][i];
		L[e] = restore[i];
	}
	state[u] = 2;
}
		
int main(){
	cin >> n >> m;
	fr(i, 0, m){
		int u, v;
		cin >> u >> v;
		--u, --v;
		g[u].pb(v);
		g[v].pb(u);
	}
	fr(j, 0, n) state[j] = 0, dep[j] = -1e6, D[j] = -1e6, L[j] = 1e6;
	fr(i, 0, n){
		if(state[i] == 2) continue;
		dfs(i);
	}
	cout<<"no"<<endl;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 340 KB Wrong answer on graph without induced cycle
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 336 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 992 KB Wrong adjacency
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 15 ms 596 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 43 ms 1284 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -