Submission #334566

# Submission time Handle Problem Language Result Execution time Memory
334566 2020-12-09T12:27:11 Z mehrdad_sohrabi Potemkin cycle (CEOI15_indcyc) C++14
0 / 100
123 ms 30700 KB
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < ll , ll >
#define F first
#define S second
#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout<<x<<'\n', 0;
using namespace std;
const int N=1e3+19;
vector <int> g[N];
ll hi[N];
vector <int> bk[N];
map <pii,bool> mp;
ll dfs(ll v,ll p){
    hi[v]=hi[p]+1;
    for (auto u : g[v]){
        if (hi[u]==0){
            dfs(u,v);
        }
        if (hi[u]<hi[v]){
            bk[v].pb(u);
        }
    }
}
ll dis[N][N];
ll par[N][N];
    ll n,m;
ll solve(ll a,ll u,ll v){
    memset(dis,63,sizeof dis);
    dis[v][a]=-1;
    dis[u][a]=-1;
    dis[v][v]=0;
    dis[u][u]=0;
    queue <int> q;
    q.push(v);
    par[v][v]=v;
    while(q.size()){
        ll z=q.front();
        q.pop();
        for (auto y : g[z]){
            if (dis[v][y]>dis[v][z]+1){
                par[v][y]=z;
                q.push(y);
                dis[v][y]=dis[v][z]+1;
            }
        }
    }
    q.push(u);
    par[u][u]=u;
    while(q.size()){
        ll z=q.front();
        q.pop();
        for (auto y : g[z]){
            if (dis[u][y]>dis[u][z]+1){
                par[u][y]=z;
                q.push(y);
                dis[u][y]=dis[u][z]+1;
            }
        }
    }
    dis[v][a]=1e9;
    dis[u][a]=1e9;
    ll id=0;
    for (int i=1;i<=n;i++){
        if (i==a || i==u || i==v){
            continue;
        }
        if (dis[v][id]+dis[u][id]>dis[v][i]+dis[u][i]){
            id=i;
        }
    }
    vector <int> ans;
    vector <int> b;
    ll z=id;
    while(z!=u){
        ans.pb(z);
        z=par[u][z];
    }
    ans.pb(u);
    ans.pb(a);
     z=par[v][id];
    while(z!=v){
        b.pb(z);
        z=par[v][z];
    }
    b.pb(v);
    reverse(b.begin(),b.end());
    for (auto uu : ans){
        cout << uu << endl;
    }
    for (auto uu : b){
        cout << uu << endl;
    }
    exit(0);
}
int32_t main(){
    sync;
    cin >> n >> m;
    for (int i=1;i<=m;i++){
        ll u,v;
        cin >> u >> v;
        g[u].pb(v);
        mp[{u,v}]=1;
        mp[{v,u}]=1;
        g[v].pb(u);
    }
    dfs(1,1);
    for (int i=1;i<=n;i++){
        for (auto u : bk[i]){
            for (auto v : bk[i]){
                if (u==v || mp[{u,v}]) continue;
                solve(i,v,u);
            }
        }
    }
    kill("no");
}

Compilation message

indcyc.cpp: In function 'll dfs(ll, ll)':
indcyc.cpp:29:1: warning: no return statement in function returning non-void [-Wreturn-type]
   29 | }
      | ^
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 620 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 620 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 748 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 620 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 876 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 1792 KB Execution killed with signal 6 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 1516 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 58 ms 15852 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 22 ms 6892 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 123 ms 30700 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -