Submission #54875

# Submission time Handle Problem Language Result Execution time Memory
54875 2018-07-05T08:37:59 Z 윤교준(#1510) Potemkin cycle (CEOI15_indcyc) C++11
30 / 100
53 ms 2412 KB
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define befv(V) ((V)[sz(V)-2])
#define sorv(V) sort(allv(V))
#define revv(V) reverse(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define upmax(a,b) (a)=max((a),(b))
#define upmin(a,b) (a)=min((a),(b))
#define rb(x) ((x)&(-(x)))
#define INF (0x3f3f3f3f)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
void fg(vector<int> G[], int a, int b) { G[a].pb(b); G[b].pb(a); }

const int MAXN = 1005;
const int MAXM = 100005;

vector<int> G[MAXN];

bitset<MAXN> C[MAXN];

int D[MAXN];
int chk[MAXN], chkn;

int O[MAXN];
int A[MAXM], B[MAXM];

int N, M;

void answer(int i, int a, int b) {
	chkn++;

	queue<int> PQ;
	chk[a] = chkn; PQ.push(a);

	bool isf = false;

	for(int idx; !PQ.empty(); PQ.pop()) {
		idx = PQ.front();

		for(int v : G[idx]) {
			if(v == i || v == a || chk[v] == chkn) continue;
			if(C[i][v] && C[i][idx]) continue;

			chk[v] = chkn;
			D[v] = idx;
			PQ.push(v);

			if(v == b) {
				isf = true;
				break;
			}
		}

		if(isf) break;
	}

	for(int i = b; i != a; i = D[i]) printf("%d ", i);
	printf("%d %d\n", a, i);
	exit(0);
}

int main() {
    //freopen("input.txt", "r", stdin);
	ios::sync_with_stdio(false);

	cin >> N >> M;
	for(int i = 1; i <= M; i++) {
		cin >> A[i] >> B[i];
		fg(G, A[i], B[i]);
		C[A[i]][B[i]] = C[B[i]][A[i]] = true;
	}

	for(int i = 1; i <= N; i++) {
		int dg = sz(G[i]);
		chkn++;

		for(int j = 0, a, b; j < dg; j++) {
			a = G[i][j]; b = -1;
			if(chk[a] == chkn) continue;

			vector<int> V; V.pb(a);

			queue<int> PQ;
			chk[a] = chkn; PQ.push(a);

			for(int idx; !PQ.empty(); PQ.pop()) {
				idx = PQ.front();

				for(int v : G[idx]) {
					if(v == i || v == a || chk[v] == chkn) continue;
					if(C[i][v] && C[i][idx]) continue;

					chk[v] = chkn;
					PQ.push(v);

					if(C[i][v]) V.pb(v);
				}
			}

			{
				int n = sz(V);
				for(int ji = 0; ji < n; ji++) for(int ki = ji+1; ki < n; ki++) {
					int j = V[ji], k = V[ki];
					if(C[j][k]) continue;

					answer(i, j, k);
				}
			}
		}
	}

	puts("no");
	return 0;
}

Compilation message

indcyc.cpp: In function 'int main()':
indcyc.cpp:84:21: warning: variable 'b' set but not used [-Wunused-but-set-variable]
   for(int j = 0, a, b; j < dg; j++) {
                     ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 360 KB Output is correct
3 Correct 2 ms 428 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 544 KB Output is correct
2 Incorrect 2 ms 668 KB Wrong answer on graph without induced cycle
# Verdict Execution time Memory Grader output
1 Correct 2 ms 668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 668 KB Wrong adjacency
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 752 KB Output is correct
2 Correct 3 ms 752 KB Output is correct
3 Incorrect 5 ms 752 KB Wrong adjacency
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 752 KB Wrong adjacency
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 1644 KB Wrong adjacency
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 1644 KB Wrong adjacency
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 53 ms 2412 KB Wrong adjacency
2 Halted 0 ms 0 KB -