# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
36221 | 2017-12-06T11:13:33 Z | mohammad_kilani | Potemkin cycle (CEOI15_indcyc) | C++14 | 546 ms | 3104 KB |
#include <bits/stdc++.h> using namespace std; #define mod 1000000007 #define oo 2000000000 const int N = 1010; int n , m , vi = 0 , vis[N] , pre[N] , comp[N]; bitset < N > con[N] ; vector< int > g[N]; vector< vector<int> > adj; void DFS(int node,int c,int cant){ vis[node] = vi; comp[node] = c; for(int i=0;i<g[node].size();i++){ if(g[node][i] == cant || con[cant][g[node][i]] || vis[g[node][i]] == vi) continue; DFS(g[node][i],c,cant); } } bool BFS(int s,int e){ vi++; queue < pair<int,int> > q; vis[s] = vi; pre[s] = s; for(int i=0;i<g[s].size();i++){ int node = g[s][i]; if(node == e || (con[node][e])) continue; vis[node] = vi; q.push(make_pair(node,s)); } while(!q.empty()){ int node = q.front().first; int last = q.front().second; q.pop(); pre[node] = last; if(node == e) return true; for(int i=0;i<g[node].size();i++){ int newnode = g[node][i]; if(vis[newnode] == vi || (con[newnode][s] && con[newnode][e])) continue; vis[newnode] = vi; q.push(make_pair(newnode,node)); } } return false; } int main() { //freopen("in.txt","r",stdin); scanf("%d%d",&n,&m); for(int i=0;i<m;i++){ int u , v; scanf("%d%d",&u,&v); g[u].push_back(v); g[v].push_back(u); con[u][v] = con[v][u] = true; } for(int i=1;i<=n;i++){ adj.clear(); vi++; memset(comp,0,sizeof(comp)); int cnt = 0 ; for(int j=1;j<=n;j++){ if(j == i || vis[j] == vi || con[j][i]) continue; DFS(j,cnt++,i); } adj.resize(cnt); for(int j=1;j<=n;j++){ if(con[i][j] && i != j){ bitset < N > in; for(int k=0;k<g[j].size();k++){ if(g[j][k] == i || con[i][g[j][k]] || in[comp[g[j][k]]]) continue; adj[comp[g[j][k]]].push_back(j); in[comp[g[j][k]]] = true; } } } for(int j=0;j<cnt;j++){ for(int k=0;k<adj[j].size();k++){ for(int l=k+1;l<adj[j].size();l++){ if(adj[j][k] == adj[j][l] || con[adj[j][k]][adj[j][l]]) continue; int cur = adj[j][l]; assert(BFS(i,cur) == true); while(pre[cur] != cur){ printf("%d ",cur); cur = pre[cur]; } printf("%d\n",cur); return 0; } } } } puts("no"); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2180 KB | Output is correct |
2 | Correct | 0 ms | 2180 KB | Output is correct |
3 | Correct | 0 ms | 2180 KB | Output is correct |
4 | Correct | 0 ms | 2180 KB | Output is correct |
5 | Correct | 0 ms | 2180 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2180 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2180 KB | Output is correct |
2 | Correct | 0 ms | 2180 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2180 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2180 KB | Output is correct |
2 | Correct | 0 ms | 2180 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 2312 KB | Output is correct |
2 | Correct | 0 ms | 2312 KB | Output is correct |
3 | Correct | 0 ms | 2312 KB | Output is correct |
4 | Correct | 19 ms | 2312 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2180 KB | Output is correct |
2 | Correct | 13 ms | 2180 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 2708 KB | Output is correct |
2 | Correct | 13 ms | 2576 KB | Output is correct |
3 | Correct | 436 ms | 2708 KB | Output is correct |
4 | Correct | 189 ms | 2576 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 2444 KB | Output is correct |
2 | Correct | 276 ms | 2444 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 39 ms | 3104 KB | Output is correct |
2 | Correct | 329 ms | 3104 KB | Output is correct |
3 | Correct | 29 ms | 2972 KB | Output is correct |
4 | Correct | 546 ms | 2972 KB | Output is correct |