Submission #564054

# Submission time Handle Problem Language Result Execution time Memory
564054 2022-05-18T13:51:24 Z piOOE Potemkin cycle (CEOI15_indcyc) C++17
30 / 100
157 ms 88276 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, M = 100000;


int A[M], B[M];

bool e[N][N];
vector<pair<int, int>> adj[N];
vector<int> g[M];

vector<int> st, sus;

bool used[M];

void dfs(int v, int p) {
    used[v] = true;
    st.push_back(v);
    for (int to: g[v]) {
        if (to != p) {
            if (!used[to]) {
                dfs(to, v);
            } else {
                while (st.back() != to) {
                    sus.push_back(st.back());
                    st.pop_back();
                }
                sus.push_back(to);
                for (int i = 0; i < sz(sus) - 1; ++i) {
                    if (A[sus[i]] == A[sus[i + 1]]) swap(A[sus[i]], B[sus[i]]);
                    else if (A[sus[i]] == B[sus[i + 1]]) {
                        swap(A[sus[i]], B[sus[i]]);
                        swap(A[sus[i + 1]], B[sus[i + 1]]);
                    } else if (B[sus[i]] == B[sus[i + 1]]) {
                        swap(A[sus[i + 1]], B[sus[i + 1]]);
                    }
                    assert(B[sus[i]] == A[sus[i + 1]]);
                }
                for (int i : sus) {
                    cout << A[i] + 1 << " ";
                }
                exit(0);
            }
        }
    }
    st.pop_back();
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, r;
    cin >> n >> r;
    for (int i = 0; i < r; ++i) {
        cin >> A[i] >> B[i];
        --A[i], --B[i];
        adj[A[i]].emplace_back(B[i], i);
        adj[B[i]].emplace_back(A[i], i);
        e[A[i]][B[i]] = e[B[i]][A[i]] = true;
    }
    for (int v = 0; v < n; ++v) {
        for (auto [a, i]: adj[v]) {
            for (auto [b, j]: adj[v]) {
                if (i != j && !e[a][b]) {
                    g[i].push_back(j);
                }
            }
        }
    }
    for (int v = 0; v < r; ++v) {
        if (!used[v]) {
            dfs(v, -1);
        }
    }
    cout << "no";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2772 KB Too short sequence
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2704 KB Too short sequence
2 Incorrect 2 ms 2644 KB Wrong answer on graph without induced cycle
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2772 KB Too short sequence
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 3028 KB Wrong adjacency
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 3284 KB Wrong answer on graph without induced cycle
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 4564 KB Wrong adjacency
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 75 ms 19840 KB Wrong adjacency
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 68 ms 48732 KB Wrong adjacency
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 118 ms 6700 KB Too short sequence
2 Correct 112 ms 6604 KB Output is correct
3 Correct 155 ms 88244 KB Too short sequence
4 Incorrect 157 ms 88276 KB Wrong answer on graph without induced cycle
5 Halted 0 ms 0 KB -