답안 #53892

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
53892 2018-07-01T14:57:51 Z paulica Potemkin cycle (CEOI15_indcyc) C++14
90 / 100
70 ms 4608 KB
#include <bits/stdc++.h>
using namespace std;

#define _ << " _ " <<
#define TRACE(x) cout << #x << " = " << x << endl

#define fi first
#define se second
typedef pair<int, int> pii;

const int MaxN = 1010, MaxR = 1e5 + 10;
int n, r;

vector<pii> e[MaxN];
bool con[MaxN][MaxN];

pii edg[MaxR];
bool vis[MaxR], stk[MaxR];

int pre[MaxR];

void dfs(int x, int y, int id) {
    vis[id] = true;
    stk[id] = true;

    for (pii z : e[y]) {
        if (!con[x][z.fi] && z.fi != x) {
            if (!vis[z.se]) {
                pre[z.se] = id;
                dfs(y, z.fi, z.se);
            } else if (stk[z.se]) {
                vector<int> cyc = {y};
                for (int u = id; cyc.size() == 1 || cyc.back() != y; u = pre[u])
                    cyc.push_back(edg[u].fi + edg[u].se - cyc.back());
                cyc.pop_back();
                
                int m = cyc.size();
                for (int len = 3; len < m; len++)
                    for (int i = 0; i < m; i++) {
                        if (con[cyc[i]][cyc[(i + len) % m]]) {
                            for (int j = (i + 1) % m; j != i; j = (j + 1) % m)
                                cout << cyc[j] << " ";
                            cout << cyc[i];

                            exit(0);                
                        }
                    }
            }
        }
    }

    stk[id] = false;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> r;
    
    for (int i = 0; i < r; i++) {
        int x, y;
        cin >> x >> y;
        
        e[x].push_back({y, i});
        e[y].push_back({x, i});

        con[x][y] = con[y][x] = true;

        edg[i] = {x, y};
    }

    for (int i = 0; i < r; i++) {
        if (!vis[i]) dfs(edg[i].fi, edg[i].se, i);
    }

    cout << "no";

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 448 KB Output is correct
3 Correct 2 ms 544 KB Output is correct
4 Correct 3 ms 544 KB Output is correct
5 Correct 2 ms 564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 564 KB Output is correct
2 Correct 2 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 692 KB Output is correct
2 Correct 3 ms 692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1104 KB Output is correct
2 Correct 3 ms 1104 KB Output is correct
3 Correct 4 ms 1136 KB Output is correct
4 Correct 4 ms 1136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1136 KB Output is correct
2 Correct 4 ms 1136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 3328 KB Output is correct
2 Incorrect 9 ms 3328 KB Repeated vertex
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 3328 KB Output is correct
2 Correct 11 ms 3328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 3840 KB Output is correct
2 Correct 70 ms 3968 KB Output is correct
3 Correct 20 ms 3968 KB Output is correct
4 Correct 45 ms 4608 KB Output is correct