Submission #527114

# Submission time Handle Problem Language Result Execution time Memory
527114 2022-02-17T02:11:26 Z joelau Potemkin cycle (CEOI15_indcyc) C++14
30 / 100
1000 ms 2500 KB
#include <bits/stdc++.h>
using namespace std;

int N,M, p[1005], depth[1005], A[1005];
vector<int> lst[1005];
bitset<1005> visited;
vector< pair<int,int> > edges;

bool cmp (pair<int,int> a, pair<int,int> b) {
    if (a.first == b.first) return depth[a.second] < depth[b.second];
    else return depth[a.first] > depth[b.first];
}

void dfs (int x, int par, int d) {
    visited[x] = 1, p[x] = par, depth[x] = d;
    for (int v: lst[x]) if (!visited[v]) dfs(v,x,d+1);
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> N >> M;
    for (int i = 0; i < M; ++i) {
        int u,v; cin >> u >> v; u--, v--;
        lst[u].push_back(v), lst[v].push_back(u);
    }
    for (int i = 0; i < N; ++i) {
        visited.reset();
        dfs(i,-1,0);
        edges.clear();
        for (int u = 0; u < N; ++u) if (visited[u]) {
            for (int v: lst[u]) if (visited[v] && depth[u] < depth[v] && depth[v]-depth[u] != 1) edges.emplace_back(u,v);
        }
        sort(edges.begin(),edges.end(),cmp);
        memset(A,0,sizeof(A));
        for (auto x: edges) {
            if (depth[x.second]-depth[x.first] > 2) {
                bool can = true;
                for (int u = x.second; u != x.first && can; u = p[u]) if (A[u] != 0) can = false;
                if (can) {
                    for (int u = x.second; u != x.first; u = p[u]) cout << u+1 << ' ';
                    cout << x.first+1;
                    return 0;
                }
            }
            A[x.second]++;
        }
    }
    cout << "no";

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 332 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Wrong adjacency
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 70 ms 460 KB Output is correct
2 Incorrect 75 ms 460 KB Expected integer, but "no" found
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Wrong adjacency
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1082 ms 1584 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 976 KB Wrong adjacency
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 22 ms 2460 KB Output is correct
2 Execution timed out 1093 ms 2500 KB Time limit exceeded
3 Halted 0 ms 0 KB -