답안 #54860

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
54860 2018-07-05T08:22:06 Z 윤교준(#1510) Potemkin cycle (CEOI15_indcyc) C++11
70 / 100
1000 ms 2448 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;
	}

	for(int i = 1; i <= N; i++) {
		int dg = sz(G[i]);
		for(int j = 0, a, b; j < dg; j++) {
			a = G[i][j]; b = -1;

			bool isf = false;

			queue<int> PQ;
			chkn++; 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][idx] && C[i][v]) continue;
					if(C[i][v] && C[a][v]) continue;

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

					if(C[i][v]) {
						b = v;
						isf = true;
						break;
					}
				}

				if(isf) break;
			}

			if(!isf) continue;

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

	puts("no");
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 492 KB Output is correct
3 Correct 2 ms 492 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 2 ms 564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 620 KB Output is correct
2 Correct 2 ms 620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 620 KB Output is correct
2 Correct 12 ms 624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 61 ms 792 KB Output is correct
2 Correct 3 ms 876 KB Output is correct
3 Correct 11 ms 876 KB Output is correct
4 Correct 155 ms 876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 876 KB Output is correct
2 Correct 94 ms 876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 70 ms 1660 KB Output is correct
2 Correct 31 ms 1660 KB Output is correct
3 Execution timed out 1053 ms 1660 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 1660 KB Output is correct
2 Execution timed out 1077 ms 1660 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 2440 KB Output is correct
2 Correct 427 ms 2448 KB Output is correct
3 Correct 363 ms 2448 KB Output is correct
4 Execution timed out 1067 ms 2448 KB Time limit exceeded