Submission #54851

# Submission time Handle Problem Language Result Execution time Memory
54851 2018-07-05T08:13:44 Z 윤교준(#1510) Potemkin cycle (CEOI15_indcyc) C++11
90 / 100
695 ms 2516 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 __cnt = 0;
int N, M;

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;
	}
	
	iota(O, O+N+1, 0);
	srand(6974);
	random_shuffle(O+1, O+N+1);

	for(int oi = 1, i; oi <= N; oi++) {
		i = O[oi];
		int dg = sz(G[i]);
		for(int j = 0; j < dg; j++) for(int k = j+1; k < dg; k++) {
			__cnt++;
			int a = G[i][j], b = G[i][k];
			if(C[a][b]) continue;

			bool isf = false;

			queue<int> PQ;
			chkn++; chk[a] = chkn; PQ.push(a);
			for(int idx; !PQ.empty(); PQ.pop()) {
				__cnt++;
				idx = PQ.front();

				for(int v : G[idx]) {
					__cnt++;
					if(v == i || (v != b && C[i][v])) continue;
					if(chk[v] == chkn) continue;
					chk[v] = chkn;
					D[v] = idx;
					if(v == b) {
						isf = true;
						break;
					}
					PQ.push(v);
				}
				if(isf) break;
			}

			if(!isf) continue;

			for(int v = b; v != a; v = D[v]) printf("%d ", v);
			printf("%d %d\n", a, i);
			return 0;
		}
		if(95000000 <= __cnt) {
			puts("no");
			return 0;
		}
	}

	puts("no");
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 452 KB Output is correct
4 Correct 2 ms 452 KB Output is correct
5 Correct 2 ms 480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 696 KB Output is correct
2 Correct 2 ms 696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 696 KB Output is correct
2 Correct 19 ms 696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 241 ms 844 KB Output is correct
2 Correct 8 ms 844 KB Output is correct
3 Correct 5 ms 844 KB Output is correct
4 Correct 69 ms 844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 844 KB Output is correct
2 Correct 159 ms 844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 525 ms 1740 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 39 ms 1740 KB Output is correct
2 Correct 695 ms 1740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 2380 KB Output is correct
2 Correct 164 ms 2516 KB Output is correct
3 Correct 207 ms 2516 KB Output is correct
4 Correct 349 ms 2516 KB Output is correct