답안 #1115954

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1115954 2024-11-21T06:09:36 Z vjudge1 Potemkin cycle (CEOI15_indcyc) C++17
20 / 100
11 ms 6992 KB
//Dost SEFEROĞLU
#include <bits/stdc++.h>
#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
#pragma GCC optimize("O3,unroll-loops")
using namespace std;
#define int long long
#define pii pair<int,int>
#define ff first
#define ss second
#define sp << " " <<    
#define all(cont) cont.begin(),cont.end()
#define vi vector<int>
int MOD = 998244353,inf = 2e18;
const int N = 1e5+50,Q = 2e5+50;

vi edges[N];
int tin[N],dep[N],par[N];
pii ans{-1,-1};
int timer = 1;

bool anc(int a,int b) {
    if (b == -1) return 0;
    return tin[a] <= tin[b];
}

void dfs(int node,int p,int der = 0,int ban = -1) {
    par[node] = p;
    dep[node] = der;
    tin[node] = timer++;
    pii maxdepshi = {-1,-1};
    int banny = ban;
    for (auto it : edges[node]) {
        if (it == p) continue;
        if (tin[it] && (ban == -1 || tin[it] > tin[ban])) {
            ban = it;
        }
    }
    for (auto it : edges[node]) {
        if (it == p) continue;
        else if (!tin[it]) dfs(it,node,der+1,ban);
        else if (dep[it] < dep[node]) maxdepshi = max(maxdepshi,{dep[it],it});
    }
    if (maxdepshi.ff != -1 && dep[node]-maxdepshi.ff >= 3 && !anc(maxdepshi.ss,banny)) {
        ans = {node,maxdepshi.ss};
    }
}   

void solve() {
    int n,m;
    cin >> n >> m;
    for (int i=1;i<=m;i++) {
        int a,b;
        cin >> a >> b;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }
    dfs(1,1);
    if (ans.ff == -1) {
        cout << "no\n";
        return;
    }
    vi v;
    int cur = ans.ff;
    while (cur != ans.ss) {
        cout << cur << " ";
        cur = par[cur];
    }
    cout << ans.ss << " ";
    cout << '\n';
}                    
                             
int32_t main() { 
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #ifdef Dodi
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
    #endif
    int t = 1;
    //cin >> t; 
    while (t --> 0) solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 1 ms 4944 KB Output is correct
4 Correct 2 ms 4944 KB Output is correct
5 Correct 2 ms 4944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 5112 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4944 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4944 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Incorrect 2 ms 4944 KB Expected integer, but "no" found
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4944 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 5968 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 5456 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 6804 KB Output is correct
2 Correct 11 ms 6992 KB Output is correct
3 Incorrect 8 ms 6480 KB Expected integer, but "no" found
4 Halted 0 ms 0 KB -