Submission #1069066

# Submission time Handle Problem Language Result Execution time Memory
1069066 2024-08-21T15:29:34 Z vjudge1 Potemkin cycle (CEOI15_indcyc) C++17
20 / 100
35 ms 3160 KB
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define ff first
#define ss second
using namespace std;
const int N = 1003, R = 100005;
int n, r;
vector<int>adj[N];
vector<int>ans;
vector<pair<int, int> > backedges[N];
int deep[N];
short vis[N];
const int unvisited = -1;
const int visited = 0;
const int past = 1;

void dfs(int u, int parent, int d){
    deep[u] = d;
    vis[u] = visited;
    for(auto v : adj[u]){
        if(v == parent)continue;
        if(vis[v] == unvisited){
            dfs(v, u, d + 1);
        }else if(vis[v] == past)continue;
        else{
            backedges[u].pb({deep[v], v});
        }
    }
    vis[u] = past;
}

vector<int>stk;

bool respond(int u, int parent, int deepest){
    vis[u] = visited;
    stk.pb(u);
    sort(backedges[u].rbegin(), backedges[u].rend());
    // mahyor a menor.
    if(!backedges[u].empty()){
        int v = backedges[u][0].ss;
        int d = deep[v];
        if(d > deepest && abs(d - deep[u]) >= 3){
            for(int i = (int)stk.size() - 1 ; stk[i] != v ; i --){
                ans.pb(stk[i]);
            }
            ans.pb(v);
            return true;
        }
        deepest = max(deepest, d);
    }
    for(auto v : adj[u]){
        if(parent == v)continue;
        if(vis[v] == visited)continue;
        if(respond(v, u, deepest))return true;
    }
    return false;
}
int main(){
    cin >> n >> r;
    for(int i = 0 ; i < r ; i ++){
        int u, v;
        cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    for(int i = 1 ; i <= n ; i ++)vis[i] = unvisited;

    dfs(1, -1, 0);
    for(int i = 1 ; i <= n ; i ++)vis[i] = unvisited;
    if(!respond(1, -1, -10))cout << "no";
    else{
        for(auto i : ans)cout << i << " ";

    }





}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 604 KB Output is correct
2 Incorrect 2 ms 508 KB Expected integer, but "no" found
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 604 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 25 ms 1996 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 1116 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 25 ms 3160 KB Output is correct
2 Correct 35 ms 3148 KB Output is correct
3 Incorrect 21 ms 2396 KB Expected integer, but "no" found
4 Halted 0 ms 0 KB -