Submission #258153

# Submission time Handle Problem Language Result Execution time Memory
258153 2020-08-05T12:51:13 Z doowey Potemkin cycle (CEOI15_indcyc) C++14
20 / 100
18 ms 2048 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 1005;
const int LOG = 14;
vector<int> T[N];
bool vis[N];

int tin[N];
int tout[N];
int dep[N];
int cc;
int par[N];
int high[N];

void dfs(int u, int pp){
    par[u] = pp;
    vis[u]=true;
    tin[u]=++cc;
    for(auto x : T[u]){
        if(x == pp){
            continue;
        }
        if(vis[x]) {
            high[u] = max(high[u], dep[x]);
            continue;
        }
        dep[x]=dep[u]+1;
        dfs(x, u);
    }
    tout[u]=cc;
}

int main(){
    fastIO;
    int n, m;
    cin >> n >> m;
    int u, v;
    for(int i = 1; i <= n; i ++ ){
        high[i]=-1;
    }
    for(int i = 0 ; i < m ; i ++ ){
        cin >> u >> v;
        T[u].push_back(v);
        T[v].push_back(u);
    }
    for(int i = 1; i <= n; i ++ ){
        if(vis[i]) continue;
        dfs(i,i);
    }
    int node;
    bool good;
    for(int i = 1; i <= n; i ++ ){
        for(auto x : T[i]){
            if(dep[i] - dep[x] + 1 >= 4){
                node = i;
                good = true;
                while(node != x){
                    if(node == i){
                        if(high[i] > dep[x]){
                            good = false;
                            break;
                        }
                    }
                    else if(high[node] >= dep[x]){
                        good = false;
                        break;
                    }
                    node = par[node];
                }
                if(good){
                    node = i;
                    while(1){
                        cout << node << " ";
                        if(node == x) break;
                        node = par[node];
                    }
                    return 0;
                }
            }
        }
    }
    cout << "no\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Expected integer, but "no" found
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 384 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Incorrect 1 ms 512 KB Expected integer, but "no" found
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 512 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 1280 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 768 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 2048 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -