Submission #257231

# Submission time Handle Problem Language Result Execution time Memory
257231 2020-08-03T23:56:14 Z super_j6 Potemkin cycle (CEOI15_indcyc) C++14
20 / 100
482 ms 1528 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);
	}
	
	for(int i = 0; i < n; i++){
		memset(d, -1, sizeof(d));
		d[i] = 0, p[i] = -1;
		dfs(i);
	}
	
	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 Correct 0 ms 384 KB Output is correct
# 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 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 384 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 22 ms 512 KB Output is correct
2 Incorrect 22 ms 504 KB Expected integer, but "no" found
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 384 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 427 ms 1144 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 264 ms 760 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 1280 KB Output is correct
2 Correct 216 ms 1528 KB Output is correct
3 Incorrect 482 ms 1236 KB Expected integer, but "no" found
4 Halted 0 ms 0 KB -