Submission #36212

# Submission time Handle Problem Language Result Execution time Memory
36212 2017-12-06T10:48:09 Z mohammad_kilani Potemkin cycle (CEOI15_indcyc) C++14
30 / 100
363 ms 3232 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] , can[N];
vector< int > g[N];

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 || 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++){
		vi++;
		int cnt = 0 ;
		for(int j=1;j<=n;j++){
			if(j == i || vis[j] == vi) continue;
			DFS(j,cnt++,i);
		}
		for(int j=0;j<g[i].size();j++){
			for(int k=j+1;k<g[i].size();k++){
				if(con[g[i][j]][g[i][k]] || comp[g[i][j]] != comp[g[i][k]]) continue;
				can[i][g[i][j]] = true;
				can[i][g[i][k]] = true;
			}
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			if(can[i][j] && can[j][i]){
				int cur = j;
				BFS(i,j);
				while(pre[cur] != cur){
					printf("%d ",cur);
					cur = pre[cur];
				}
				printf("%d\n",cur);
				return 0;
			}
		}
	}
	puts("no");
	return 0;
}

Compilation message

indcyc.cpp: In function 'void DFS(int, int, int)':
indcyc.cpp:13:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<g[node].size();i++){
               ^
indcyc.cpp: In function 'bool BFS(int, int)':
indcyc.cpp:24:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<g[s].size();i++){
               ^
indcyc.cpp:36:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<g[node].size();i++){
                ^
indcyc.cpp: In function 'int main()':
indcyc.cpp:63:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=0;j<g[i].size();j++){
                ^
indcyc.cpp:64:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int k=j+1;k<g[i].size();k++){
                   ^
indcyc.cpp:48:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&m);
                     ^
indcyc.cpp:51:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&u,&v);
                      ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2308 KB Output is correct
2 Correct 0 ms 2308 KB Output is correct
3 Correct 0 ms 2308 KB Output is correct
4 Correct 0 ms 2308 KB Output is correct
5 Correct 0 ms 2308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 2308 KB Integer 0 violates the range [1, 10]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 2308 KB Integer 0 violates the range [1, 100]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 2440 KB Wrong answer on graph without induced cycle
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 2308 KB Integer 0 violates the range [1, 300]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 299 ms 2836 KB Integer 0 violates the range [1, 1000]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 136 ms 2572 KB Integer 0 violates the range [1, 1000]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 273 ms 3232 KB Output is correct
2 Correct 256 ms 3232 KB Output is correct
3 Incorrect 363 ms 3100 KB Integer 0 violates the range [1, 1000]
4 Halted 0 ms 0 KB -