# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
47929 | 2018-05-09T08:11:22 Z | Extazy | Potemkin cycle (CEOI15_indcyc) | C++17 | 25 ms | 1644 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 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; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int 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); } memset(pos,-1,sizeof(pos)); for(i=1;i<=n;i++) if(!used[i]) { if(dfs(i)) { return 0; } } 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 | 488 KB | Output is correct |
3 | Correct | 2 ms | 488 KB | Output is correct |
4 | Correct | 2 ms | 488 KB | Output is correct |
5 | Correct | 2 ms | 488 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 488 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 488 KB | Wrong adjacency |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 520 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 520 KB | Wrong adjacency |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 648 KB | Wrong answer on graph without induced cycle |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 648 KB | Wrong adjacency |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 13 ms | 1132 KB | Wrong adjacency |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 7 ms | 1132 KB | Wrong adjacency |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 25 ms | 1644 KB | Wrong adjacency |
2 | Halted | 0 ms | 0 KB | - |