답안 #588468

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
588468 2022-07-03T10:46:11 Z Blagojce Potemkin cycle (CEOI15_indcyc) C++11
50 / 100
1000 ms 2596 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;
mt19937 _rand(time(NULL));

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

int parent[mxn];
bool adj[mxn][mxn];

void dfs(int u){
	state[u] = 1;
	vector<int> restore;
	restore.resize(g[u].size());
	fr(i, 0, (int)g[u].size()){
		auto e = g[u][i];
		restore[i] = L[e];
		
	}
	for(auto e : g[u]){
		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] != 1e6 && L[x] <= dep[u]) || (D[x] !=-1e6 && dep[e] <= D[x])){
					ok = false;
					break;
				}
			}
			if(x == parent[x]) break;
			x = parent[x];
		}
		if(ok){
			x = u;
			vector<int> sol;
			while(dep[x] >= dep[e]){
				sol.pb(x);
				if(x == parent[x]) break;
				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);
		adj[u][v] = adj[v][u] = true;
	}
	
	fr(i, 0, n){
		fr(j, 0, n) state[j] = 0, dep[j] = -1e6, D[j] = -1e6, L[j] = 1e6, parent[j] = j;
		dep[i] = 0;
		fr(j, 0, n){
			shuffle(all(g[j]), _rand);
		}
		dfs(i);
	}
	cout<<"no"<<endl;
}
/*
6 8
1 2
2 3
3 4
2 5
6 1
5 6
4 2
4 1


*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 480 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 66 ms 724 KB Output is correct
2 Correct 8 ms 768 KB Output is correct
3 Correct 19 ms 816 KB Output is correct
4 Correct 131 ms 804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 65 ms 696 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1086 ms 2340 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1098 ms 1696 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1094 ms 2596 KB Time limit exceeded
2 Halted 0 ms 0 KB -