Submission #53890

# Submission time Handle Problem Language Result Execution time Memory
53890 2018-07-01T14:53:17 Z paulica Potemkin cycle (CEOI15_indcyc) C++14
70 / 100
68 ms 7108 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; u != z.se; u = pre[u])
                    cyc.push_back(edg[u].fi + edg[u].se - cyc.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;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 396 KB Output is correct
2 Correct 2 ms 488 KB Output is correct
3 Correct 3 ms 488 KB Output is correct
4 Correct 2 ms 620 KB Output is correct
5 Correct 2 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 740 KB Repeated vertex
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 752 KB Output is correct
2 Correct 3 ms 888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1236 KB Output is correct
2 Correct 3 ms 1332 KB Output is correct
3 Correct 5 ms 1372 KB Output is correct
4 Correct 4 ms 1468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1468 KB Output is correct
2 Correct 5 ms 1468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 4100 KB Output is correct
2 Incorrect 10 ms 4100 KB Repeated vertex
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 4100 KB Output is correct
2 Correct 13 ms 4100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 5816 KB Output is correct
2 Correct 68 ms 6608 KB Output is correct
3 Incorrect 19 ms 7108 KB Repeated vertex
4 Halted 0 ms 0 KB -