Submission #563886

# Submission time Handle Problem Language Result Execution time Memory
563886 2022-05-18T08:47:22 Z piOOE Potemkin cycle (CEOI15_indcyc) C++17
50 / 100
1000 ms 1912 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 used[N];
vector<int> st;
int n;

void dfs(int v, int p, int d) {
    st.push_back(v);
    used[v] = d;
    int gg = -1;
    for (int to = 0; to < n; ++to) {
        if (to != p && to != v && e[v][to] && used[to]) {
            if (gg == -1 || used[to] > used[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 = 0; to < n; ++to) {
        if (to != p && e[v][to] && !e[p][to]) {
            dfs(to, v, d + 1);
        }
    }
    st.pop_back();
    used[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;
    }
    for (int v = 0; v < n; ++v) {
        used[v] = true;
        st.push_back(v);
        for (int to = 0; to < n; ++to) {
            if (e[v][to]) {
                dfs(to, v, 2);
            }
        }
        st.pop_back();
        used[v] = false;
    }
    cout << "no";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 3 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 111 ms 420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1060 ms 596 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 596 KB Output is correct
2 Execution timed out 1087 ms 596 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1042 ms 1620 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 256 ms 1432 KB Output is correct
2 Execution timed out 1080 ms 1360 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 36 ms 1448 KB Output is correct
2 Correct 234 ms 1364 KB Output is correct
3 Correct 144 ms 1912 KB Output is correct
4 Execution timed out 1090 ms 1804 KB Time limit exceeded
5 Halted 0 ms 0 KB -