Submission #563915

# Submission time Handle Problem Language Result Execution time Memory
563915 2022-05-18T09:23:41 Z piOOE Potemkin cycle (CEOI15_indcyc) C++17
60 / 100
1000 ms 2344 KB
#include <bits/stdc++.h>

using namespace std;

#define all(x) begin(x), end(x)
#define sz(x) ((int)size(x))
#define trace(x) cout << #x << ": " << (x) << endl;

typedef long long ll;

const int N = 1000;

bool e[N][N];

int depth[N];
vector<int> st;
int n;
bool used[N], in_st[N], ff[N];
vector<int> g[N];

void dfs(int v, int p, int d) {
    used[v] = true;
    st.push_back(v);
    depth[v] = d;
    in_st[v] = true;
    int gg = -1;
    for (int to:g[v]) {
        if (to != p && in_st[to]) {
            if (gg == -1 || depth[to] > depth[gg]) {
                gg = to;
            }
        }
    }
    if (gg != -1) {
        cout << gg + 1 << " ";
        while (st.back() != gg) {
            cout << st.back() + 1 << " ";
            st.pop_back();
        }
        exit(0);
    }
    for (int to: g[v]) {
        if (to != p && !e[p][to] && !ff[to]) {
            dfs(to, v, d + 1);
        }
    }
    st.pop_back();
    in_st[v] = false;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int r;
    cin >> n >> r;
    for (int i = 0; i < r; ++i) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        e[a][b] = e[b][a] = true;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    for (int v = 0; v < n; ++v) {
        memset(used, 0, sizeof(used));
        depth[v] = 1;
        used[v] = true;
        in_st[v] = true;
        st.push_back(v);
        for (int to: g[v]) {
            dfs(to, v, 2);
        }
        st.pop_back();
        depth[v] = 0;
        in_st[v] = false;
        ff[v] = true;
    }
    cout << "no";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 6 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1080 ms 596 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 194 ms 676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1083 ms 1876 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1492 KB Output is correct
2 Execution timed out 1085 ms 1492 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 25 ms 1748 KB Output is correct
2 Correct 169 ms 2036 KB Output is correct
3 Correct 11 ms 2260 KB Output is correct
4 Execution timed out 1084 ms 2344 KB Time limit exceeded
5 Halted 0 ms 0 KB -