Submission #334567

# Submission time Handle Problem Language Result Execution time Memory
334567 2020-12-09T12:27:45 Z mehrdad_sohrabi Potemkin cycle (CEOI15_indcyc) C++14
20 / 100
140 ms 23532 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;
void 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;
void 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");
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8556 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 8556 KB Wrong adjacency
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 8556 KB Wrong adjacency
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 8684 KB Wrong adjacency
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 9068 KB Wrong answer on graph without induced cycle
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 9068 KB Wrong adjacency
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 71 ms 16108 KB Wrong adjacency
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 33 ms 11884 KB Wrong adjacency
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 140 ms 23532 KB Wrong adjacency
2 Halted 0 ms 0 KB -