# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
25074 | 2017-06-20T06:02:01 Z | 시제연(#1054) | Potemkin cycle (CEOI15_indcyc) | C++ | 383 ms | 4168 KB |
#include <bits/stdc++.h> using namespace std; vector<int> lis[1100]; int n, m; int par[1100]; bool chk[1100]; bool adj[1100][1100]; bool dead[1100]; int fin(int a) {return par[a] = ((par[a]==a)?a:fin(par[a]));} void uni(int a, int b) { a = fin(a), b = fin(b); par[a] = b; } bool vis[1100]; int pa[1100]; void print_path(int v, int q, int r) { int i; queue<int> qu; vis[v] = vis[q] = true; pa[v] = -1; pa[q] = v; qu.push(q); while(!qu.empty()) { int here = qu.front(); qu.pop(); for (i=0;i<lis[here].size();i++) { int there = lis[here][i]; if (dead[there]||vis[there]||adj[here][there]) continue; vis[there] = true; qu.push(there); pa[there] = here; if (there==r) { int p = there; while(~p) { printf("%d ",p+1); p = pa[p]; } return; } } } } bool check(int v) { int i, j; memset(chk,0,sizeof(chk)); memset(par,-1,sizeof(par)); chk[v] = true; for (i=0;i<n;i++) par[i] = i; for (i=0;i<lis[v].size();i++) chk[lis[v][i]] = true; for (i=0;i<lis[v].size();i++) { int q = lis[v][i]; if (dead[q]) continue; for (j=0;j<lis[q].size();j++) { int r = lis[q][j]; if (dead[r]) continue; if (r==v||!chk[r]) continue; adj[q][r] = true; } } for (i=0;i<n;i++) { if (dead[i]) continue; for (j=0;j<lis[i].size();j++) { int there = lis[i][j]; if (i==v||there==v||dead[there]||adj[i][there]) continue; uni(i,there); } } for (i=0;i<lis[v].size();i++) { int q = lis[v][i]; if (dead[q]) continue; for (j=i+1;j<lis[v].size();j++) { int r = lis[v][j]; if (dead[r]) continue; if (fin(q)==fin(r)&&!adj[q][r]) { print_path(v,q,r); return true; } adj[q][r] = false; } } return false; } bool dnc(int v) { int i; if (check(v)) return true; dead[v] = true; for (i=0;i<lis[v].size();i++) if (!dead[lis[v][i]]) if (dnc(lis[v][i])) return true; return false; } int main() { int i; //freopen("input","r",stdin); scanf("%d%d",&n,&m); for (i=0;i<m;i++) { int a, b; scanf("%d%d",&a,&b); a--;b--; lis[a].push_back(b); lis[b].push_back(a); } if (!dnc(0)) printf("no\n"); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 3244 KB | Output is correct |
2 | Correct | 0 ms | 3244 KB | Output is correct |
3 | Correct | 0 ms | 3244 KB | Output is correct |
4 | Correct | 0 ms | 3244 KB | Output is correct |
5 | Correct | 0 ms | 3244 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 3244 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 3244 KB | Output is correct |
2 | Correct | 0 ms | 3244 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 3244 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 3244 KB | Wrong adjacency |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 3376 KB | Output is correct |
2 | Incorrect | 6 ms | 3376 KB | Wrong adjacency |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 3244 KB | Wrong adjacency |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 316 ms | 3772 KB | Wrong adjacency |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 9 ms | 3508 KB | Wrong adjacency |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 273 ms | 4168 KB | Output is correct |
2 | Correct | 383 ms | 4168 KB | Output is correct |
3 | Incorrect | 33 ms | 4036 KB | Wrong adjacency |
4 | Halted | 0 ms | 0 KB | - |