Submission #257229

# Submission time Handle Problem Language Result Execution time Memory
257229 2020-08-03T23:50:32 Z super_j6 Potemkin cycle (CEOI15_indcyc) C++14
10 / 100
17 ms 2048 KB
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string.h>
#include <set>
using namespace std;
#define endl '\n'
#define ll long long
#define pi pair<int, int>
#define f first
#define s second

const int mxn = 1000;
int n, m;
int d[mxn], p[mxn];
vector<int> g[mxn];
set<int, greater<int>> s;

void dfs(int c){
	bool t = 0;
	for(int i : g[c]) t |= (~d[i] && d[c] - d[i] == 2);
	if(t){
		s.insert(d[c] - 2);
	}else{
		int x = -1;
		for(int i : g[c]) if(i != p[c] && ~d[i] && (!~x || d[i] > d[x])) x = i;
		if(~x && d[x] > *s.begin()){
			cout << c + 1;
			for(int i = p[c]; ~i && d[i] >= d[x]; i = p[i]) cout << " " << i + 1;
			cout << endl;
			exit(0);
		}
	}
	for(int i : g[c]){
		if(~d[i]) continue;
		d[i] = d[c] + 1, p[i] = c;
		dfs(i);
	}
	if(t) s.erase(d[c] - 2);
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> m;
	
	for(int i = 0; i < m; i++){
		int u, v;
		cin >> u >> v;
		u--, v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	
	memset(d, -1, sizeof(d));
	d[0] = 0, p[0] = -1;
	dfs(0);
	
	cout << "no" << endl;

	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 384 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 384 KB Expected integer, but "no" found
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 384 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Incorrect 1 ms 512 KB Expected integer, but "no" found
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 1408 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 768 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 2048 KB Output is correct
2 Correct 16 ms 2048 KB Output is correct
3 Incorrect 13 ms 1664 KB Expected integer, but "no" found
4 Halted 0 ms 0 KB -