답안 #564108

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
564108 2022-05-18T15:06:00 Z piOOE Potemkin cycle (CEOI15_indcyc) C++17
30 / 100
564 ms 336248 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], C[2][M];

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

vector<pair<int, int>> st, sus;

bool used[2][M];
int usd[N], T = 1;

void dfs(int t, int v, pair<int, int> p) {
    used[t][v] = true;
    usd[C[t][v]] = T;
    st.emplace_back(t, v);
    for (auto to: g[t][v]) {
        if (to != p) {
            if (!used[to.first][to.second]) {
                dfs(to.first, to.second, {t, v});
            } else if (usd[C[to.first][to.second]] == T){
                memset(usd, 0, sizeof(usd));
                st.emplace_back(to);
                while (!usd[C[st.back().first][st.back().second]]) {
                    auto mm = st.back();
                    cout << C[mm.first][mm.second] + 1 << " ";
                    usd[C[mm.first][mm.second]] = true;
                    st.pop_back();
                }
                exit(0);
            }
        }
    }
    usd[C[t][v]] = 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];
        C[0][i] = A[i];
        C[1][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]) {
                    int t1 = (B[i] == a);
                    int t2 = (B[j] == v);
                    g[t1][i].emplace_back(t2, j);
                    g[t2][j].emplace_back(t1, i);
                }
            }
        }
    }
    for (int v = 0; v < r; ++v) {
        if (!used[0][v]) {
            ++T;
            dfs(0, v, {-1, -1});
        }
        if (!used[1][v]) {
            ++T;
            dfs(1, v, {-1, -1});
        }
    }
    cout << "no";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5076 KB Output is correct
2 Correct 3 ms 5076 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 3 ms 5076 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5076 KB Too short sequence
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5076 KB Too short sequence
2 Incorrect 3 ms 5076 KB Wrong answer on graph without induced cycle
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5204 KB Too short sequence
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 5972 KB Too short sequence
2 Incorrect 5 ms 6240 KB Wrong answer on graph without induced cycle
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 6228 KB Wrong answer on graph without induced cycle
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 11320 KB Too short sequence
2 Incorrect 15 ms 11608 KB Wrong answer on graph without induced cycle
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 184 ms 64412 KB Too short sequence
2 Correct 53 ms 16848 KB Too short sequence
3 Incorrect 164 ms 64812 KB Wrong answer on graph without induced cycle
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 239 ms 183896 KB Too short sequence
2 Incorrect 266 ms 199552 KB Wrong answer on graph without induced cycle
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 149 ms 10316 KB Too short sequence
2 Correct 141 ms 9124 KB Output is correct
3 Correct 561 ms 336248 KB Too short sequence
4 Incorrect 564 ms 336184 KB Wrong answer on graph without induced cycle
5 Halted 0 ms 0 KB -