Submission #334567

#TimeUsernameProblemLanguageResultExecution timeMemory
334567mehrdad_sohrabiPotemkin cycle (CEOI15_indcyc)C++14
20 / 100
140 ms23532 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...