답안 #37657

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
37657 2017-12-26T16:58:06 Z nickyrio Potemkin cycle (CEOI15_indcyc) C++14
50 / 100
1000 ms 3444 KB
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = a; i<= b; ++i)
#define FORD(i, a, b) for (int i = a; i>=b; --i)
#define REP(i, a) for (int i = 0; i<a; ++i)
#define DEBUG(x) { cerr << #x << " = " << x << endl; }
#define Arr(A, l, r) { cerr << #A  << " = "; FOR(_, l, r) cerr << A[_] << ' '; cerr << endl; }
#define N 1111
#define pp pair<int, int>
#define next __next
#define prev __prev
#define __builtin_popcount __builtin_popcountll
#define bit(S, i) (((S) >> i) & 1)
#define IO cin.tie(NULL);cout.tie(NULL);
#define taskname "Test"
using namespace std;
int n, m, p[N];
vector<int> e[N];
queue<int> q;
bitset<N> banned[N], parent[N];
void Try(int s) {
    while (!q.empty()) q.pop();
    FOR(i, 1, n) {
        p[i] = 0;
        banned[i].reset();
        parent[i].reset();
    }
    q.push(s);
    parent[s].set(s);
    p[s] = -1;
    while (!q.empty()) {
        int u = q.front();q.pop();
        for (int v : e[u]) if (v != p[u]) {
            if (p[v] == 0) {
            }
            else {
                if ((parent[u] & parent[v]).count() > 1) continue;
            //    FOR(i, 1, n) if (banned[v][i]) cerr << i << ' '; cerr << endl;
            //    FOR(i, 1, n) if (parent[u][i]) cerr << i << ' '; cerr << endl;
                if (parent[u].count() + parent[v].count() > 4 && (banned[v] & parent[u]).count() == 0) {
                    vector<int> res;
                    int t = u;
                    while (t != s) {
                        res.push_back(t);
                        t = p[t];
                    }
                    while (!res.empty()) cout << res.back() << ' ',res.pop_back();
                    t = v;
                    while (t != -1) {
                        cout << t << ' ';
                        t = p[t];
                    }
                    exit(0);
                }
                banned[u].set(v);
                banned[v].set(u);
            }
        }
        for (int v : e[u]) if (v != p[u]) {
            if (p[v] == 0) {
                p[v] = u;
                banned[v] = banned[u];
                parent[v] = parent[u];
                parent[v].set(v);
                q.push(v);
            }
        }
    }
}
int main() {
    IO;ios::sync_with_stdio(false);
    cin >> n >> m;
    REP(i, m) {
        int u, v;
        cin >> u >> v;
        e[u].push_back(v);
        e[v].push_back(u);
    }
    FOR(i, 1, n) Try(i);
    cout << "no";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2520 KB Output is correct
2 Correct 0 ms 2520 KB Output is correct
3 Correct 0 ms 2520 KB Output is correct
4 Correct 0 ms 2520 KB Output is correct
5 Correct 0 ms 2520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2520 KB Output is correct
2 Correct 0 ms 2520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 49 ms 2520 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 516 ms 2520 KB Output is correct
2 Correct 0 ms 2520 KB Output is correct
3 Correct 13 ms 2520 KB Output is correct
4 Correct 649 ms 2520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 433 ms 2520 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 139 ms 3048 KB Output is correct
2 Correct 93 ms 2784 KB Output is correct
3 Execution timed out 1000 ms 3048 KB Execution timed out
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1000 ms 2784 KB Execution timed out
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1000 ms 3444 KB Execution timed out
2 Halted 0 ms 0 KB -