Submission #34363

# Submission time Handle Problem Language Result Execution time Memory
34363 2017-11-10T17:49:54 Z mohammad_kilani Potemkin cycle (CEOI15_indcyc) C++14
10 / 100
1000 ms 2452 KB
#include <bits/stdc++.h>
using namespace std;
#define mod 1000007
#define oo 2000000000
const int N = 1010;
bitset < N > connected[N] , con2[N] , vis , vis2;
bitset< N * N > bridge;
vector< pair<int,int> > g[N] ; 
vector< int > g2[N];
int n , m , dfs_low[N], dfs_num[N] , cur = 0 ;
void DFS(int node){
	vis[node] = true;
	dfs_low[node] = dfs_num[node] = cur++;
	for(int i=0;i<g[node].size();i++){
		int newnode = g[node][i].first;
		if(vis[newnode]) dfs_low[node] = min(dfs_low[node],dfs_num[node]);
		else{
			DFS(newnode);
			dfs_low[node] = min(dfs_low[node],dfs_low[newnode]);
			if(dfs_low[node] > dfs_low[newnode]){
				bridge[g[node][i].second] = true;
			}
		}
	}
}

void DFS2(vector<int> &v,int node){
	vis2[node] = true;
	v.push_back(node);
	for(int i=0;i<g2[node].size();i++){
		if(vis2[g2[node][i]] && v.size() >= 4){
			return;
		}
		else if(vis2[g2[node][i]]) continue;
		DFS2(v,g2[node][i]);
		return;
	}
}

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);
		connected[u][v] = true;
		connected[v][u] = true;
		con2[u][v] = con2[v][u] = true;
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			for(int k=1;k<=n;k++){
				if(i == j || j == k || i == k) continue;
				if(connected[i][j] == 1&& connected[i][k] == 1&& connected[j][k] == 1){
					con2[i][j] = con2[j][i] = con2[i][k] = con2[k][i] = con2[j][k] = con2[k][j] = 0;
				}
			}
		}
	}
	int cnt = 0 ;
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			if(con2[i][j] == 1){
				g[i].push_back(make_pair(j,cnt));
				g[j].push_back(make_pair(i,cnt++));
			}
		}
	}
	for(int i=1;i<=n;i++){
		if(!vis[i]) DFS(i);
	}	
	for(int i=1;i<=n;i++){
		for(int j=0;j<g[i].size();j++){
			if(bridge[g[i][j].second]) continue;
			g2[i].push_back(g[i][j].first);
		}
	}
	vector<int> ans;
	for(int i=1;i<=n;i++){
		if(g2[i].size() > 0){
			DFS2(ans,i);
			break;
		}
	}
	if(ans.size() == 0){
		puts("no");
		return 0;
	}
	for(int i=0;i<ans.size();i++) printf((i == 0 ? "%d" : " %d"),ans[i]);
	puts("");
	return 0;
}

Compilation message

indcyc.cpp: In function 'void DFS(int)':
indcyc.cpp:14:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<g[node].size();i++){
               ^
indcyc.cpp: In function 'void DFS2(std::vector<int>&, int)':
indcyc.cpp:30:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<g2[node].size();i++){
               ^
indcyc.cpp: In function 'int main()':
indcyc.cpp:73:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=0;j<g[i].size();j++){
                ^
indcyc.cpp:89:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<ans.size();i++) printf((i == 0 ? "%d" : " %d"),ans[i]);
               ^
indcyc.cpp:42: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:45: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 2452 KB Output is correct
2 Incorrect 0 ms 2452 KB Wrong answer on graph without induced cycle
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2452 KB Too short sequence
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 2452 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 2452 KB Wrong adjacency
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 2452 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 53 ms 2452 KB Wrong answer on graph without induced cycle
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 53 ms 2452 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1000 ms 2452 KB Execution timed out
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1000 ms 2452 KB Execution timed out
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 699 ms 2452 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -