답안 #257562

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
257562 2020-08-04T12:08:24 Z super_j6 Potemkin cycle (CEOI15_indcyc) C++14
10 / 100
9 ms 6528 KB
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
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, mxm = 100000;
int n, m;
int u[mxn], v[mxn];
bool a[mxn][mxn];
vector<int> g[mxn];
int vis[mxm], p[mxm];
vector<int> gr[mxm];

void dfs(int c){
	vis[c] = 1;
	for(int i : gr[c]){
		if(!vis[i]){
			p[i] = c;
			dfs(i);
		}else if(i != p[c]){
			for(int j = 0; j < 2; j++){
				for(int l = 0; l < 2; l++){
					if(v[i] == u[c]) goto hell;
					swap(u[i], v[i]);
				}
				swap(u[c], v[c]);
			}
			hell:;
			cout << u[i] + 1;
			for(int j = c; ~j && u[j] != u[i]; j = p[j]){
				cout << " " << u[j] + 1;
				if(~p[j] && u[p[j]] != v[j]) swap(u[p[j]], v[p[j]]);
			}
			cout << endl;
			exit(0);
		}
	}
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> m;
	
	for(int i = 0; i < m; i++){
		cin >> u[i] >> v[i];
		u[i]--, v[i]--;
		a[u[i]][v[i]] = a[v[i]][u[i]] = 1;
		g[u[i]].push_back(i);
		g[v[i]].push_back(i);
	}
	
	for(int i = 0; i < n; i++)
	for(int j = 0; j < g[i].size(); j++)
	for(int l = 0; l < j; l++){
		int x = i ^ u[g[i][j]] ^ v[g[i][j]], y = i ^ u[g[i][l]] ^ v[g[i][l]];
		if(!a[x][y]) gr[g[i][j]].push_back(g[i][l]), gr[g[i][l]].push_back(g[i][j]);
	}
	
	p[0] = -1;
	dfs(0);
	
	cout << "no" << endl;

	return 0;
}

Compilation message

indcyc.cpp: In function 'int main()':
indcyc.cpp:62:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int j = 0; j < g[i].size(); j++)
                 ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Correct 2 ms 2688 KB Output is correct
4 Correct 2 ms 2688 KB Output is correct
5 Correct 2 ms 2688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2688 KB Repeated vertex
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2688 KB Repeated vertex
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2816 KB Repeated vertex
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 3072 KB Repeated vertex
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 3072 KB Wrong answer on graph without induced cycle
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3584 KB Too short sequence
2 Incorrect 4 ms 3456 KB Wrong answer on graph without induced cycle
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 3968 KB Too short sequence
2 Correct 4 ms 3840 KB Too short sequence
3 Incorrect 5 ms 3968 KB Wrong answer on graph without induced cycle
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 6528 KB Too short sequence
2 Incorrect 8 ms 6528 KB Wrong answer on graph without induced cycle
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 4480 KB Too short sequence
2 Incorrect 7 ms 4992 KB Wrong answer on graph without induced cycle
3 Halted 0 ms 0 KB -