답안 #1069072

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1069072 2024-08-21T15:37:05 Z vjudge1 Potemkin cycle (CEOI15_indcyc) C++17
30 / 100
1000 ms 2396 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;
    }
    stk.pop_back();
    vis[u] = past;
    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 << " ";

    }





}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Too short sequence
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Too short sequence
2 Incorrect 0 ms 348 KB Wrong answer on graph without induced cycle
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Too short sequence
2 Execution timed out 1063 ms 348 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1039 ms 600 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1040 ms 344 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1051 ms 1628 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 860 KB Too short sequence
2 Execution timed out 1084 ms 1044 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 2396 KB Output is correct
2 Execution timed out 1084 ms 2356 KB Time limit exceeded
3 Halted 0 ms 0 KB -