# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
47932 | 2018-05-09T08:16:27 Z | Extazy | Potemkin cycle (CEOI15_indcyc) | C++17 | 185 ms | 2264 KB |
#include <bits/stdc++.h> #define endl '\n' using namespace std; const int N = 1007; int n,m; vector < int > v[N]; int st[N],pos[N],sz; bool used[N]; vector < int > ans; bool have[N][N]; bool cmp_pos(int a, int b) { return pos[a]>pos[b]; } void print() { for(int i=0;i<(int)(ans.size());i++) { if(i>0) printf(" "); printf("%d", ans[i]); } printf("\n"); } bool dfs(int node, int from=-1) { used[node]=true; st[++sz]=node; pos[node]=sz; int i,len,last=-1; vector < int > in; for(i=0;i<(int)(v[node].size());i++) if(v[node][i]!=from && pos[v[node][i]]!=-1) { in.push_back(v[node][i]); } sort(in.begin(),in.end(),cmp_pos); for(i=0;i<(int)(in.size());i++) { if(last==-1) len=pos[node]-pos[in[i]]+1; else len=last-pos[in[i]]+2; if(len>3) { if(last==-1) { for(i=pos[in[i]];i<=pos[node];i++) ans.push_back(st[i]); } else { for(i=pos[in[i]];i<=last;i++) ans.push_back(st[i]); ans.push_back(node); } //print(); return true; } last=pos[in[i]]; } for(i=0;i<(int)(v[node].size());i++) if(!used[v[node][i]]) if(dfs(v[node][i],node)) { return true; } --sz; pos[node]=-1; return false; } bool check() { int i,j; for(i=0;i<(int)(ans.size());i++) { for(j=i+2;j<(int)(ans.size())-(i==0);j++) { if(have[ans[i]][ans[j]]) return false; } } return true; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int it,i,x,y; scanf("%d %d", &n, &m); for(i=1;i<=m;i++) { scanf("%d %d", &x, &y); v[x].push_back(y); v[y].push_back(x); have[x][y]=have[y][x]=true; } for(it=1;it<=30;it++) { for(i=1;i<=n;i++) { random_shuffle(v[i].begin(),v[i].end()); } memset(used,0,sizeof(used)); memset(pos,-1,sizeof(pos)); ans.clear(); sz=0; for(i=1;i<=n;i++) if(!used[i]) { if(dfs(i)) { if(check()) { print(); return 0; } else { break; } } } } printf("no\n"); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 428 KB | Output is correct |
4 | Correct | 2 ms | 508 KB | Output is correct |
5 | Correct | 2 ms | 508 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 512 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 688 KB | Output is correct |
2 | Correct | 2 ms | 688 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 700 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 4 ms | 728 KB | Expected integer, but "no" found |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 1008 KB | Output is correct |
2 | Incorrect | 8 ms | 1008 KB | Expected integer, but "no" found |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 8 ms | 1080 KB | Expected integer, but "no" found |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 91 ms | 2264 KB | Expected integer, but "no" found |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 40 ms | 2264 KB | Expected integer, but "no" found |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 185 ms | 2264 KB | Expected integer, but "no" found |
2 | Halted | 0 ms | 0 KB | - |