Submission #245233

# Submission time Handle Problem Language Result Execution time Memory
245233 2020-07-05T19:41:02 Z thecodingwizard Potemkin cycle (CEOI15_indcyc) C++11
0 / 100
171 ms 99828 KB
#include <bits/stdc++.h>

using namespace std;

#define vi vector<int>
#define ii pair<int, int>
#define f first
#define s second
#define vii vector<ii>

vii adj[1000];
bool conn[1000][1000];
vii edges;
vi adj2[100000];
bool vis[100000];

vector<int> S;
void dfs(int u, int p) {
    if (vis[u]) {
        vector<int> ans;
        int first = -1;
        bool second = true;
        while (true) {
            int x = S.back(); S.pop_back();
            if (first == -1) {
                first = x;
                continue;
            }
            if (second) {
                second = false;
                if (edges[x].f == edges[first].f || edges[x].f == edges[first].s) {
                    ans.push_back(edges[x].f);
                    ans.push_back(edges[x].s);
                } else if (edges[x].s == edges[first].s || edges[x].s == edges[first].s) {
                    ans.push_back(edges[x].s);
                    ans.push_back(edges[x].s);
                } else {
                    assert(false);
                }
            } else {
                if (!ans.empty() && ans.back() == edges[x].f) {
                    ans.push_back(edges[x].s);
                } else {
                    assert(ans.back() == edges[x].s);
                    ans.push_back(edges[x].f);
                }
            }
            if (u == x) break;
        }
        for (int x : ans) cout << x+1 << " ";
        cout << endl;
        exit(0);
    }
    vis[u] = true;
    S.push_back(u);
    for (auto v : adj2[u]) {
        if (v != p) dfs(v, u);
    }
    S.pop_back();
}

int main() {
    int n, r; cin >> n >> r;
    for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) conn[i][j] = false;

    for (int i = 0; i < r; i++) {
        vis[i] = false;
        int a, b; cin >> a >> b; --a; --b;
        conn[a][b] = true;
        conn[b][a] = true;
        edges.push_back({a,b});
        adj[a].push_back({b,i});
        adj[b].push_back({a,i});
    }

    for (int i = 0; i < r; i++) {
        int a = edges[i].f, b = edges[i].s;
        for (auto v : adj[a]) {
            if (v.f == b || conn[b][v.f]) continue;
            adj2[v.s].push_back(i);
        }
        for (auto v : adj[b]) {
            if (v.f == a || conn[a][v.f]) continue;
            adj2[v.s].push_back(i);
        }
    }

    for (int i = 0; i < r; i++) {
        if (!vis[i]) dfs(i, i);
    }
    cout << "no" << endl;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 9 ms 5248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 9 ms 5352 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 9 ms 5248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 10 ms 5504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 11 ms 6144 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 15 ms 6528 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 18 ms 9216 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 149 ms 41560 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 171 ms 99828 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 159 ms 12396 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -