Submission #527083

# Submission time Handle Problem Language Result Execution time Memory
527083 2022-02-17T01:24:14 Z joelau Potemkin cycle (CEOI15_indcyc) C++14
20 / 100
28 ms 3156 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) if (!visited[i]) dfs(i,-1,0);
    for (int u = 0; u < N; ++u) for (int v: lst[u]) if (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 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 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 Incorrect 1 ms 332 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 468 KB Output is correct
2 Incorrect 1 ms 384 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 Incorrect 15 ms 1544 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 972 KB Wrong adjacency
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 23 ms 2560 KB Output is correct
2 Correct 28 ms 3156 KB Output is correct
3 Incorrect 26 ms 2212 KB Wrong adjacency
4 Halted 0 ms 0 KB -