Submission #34364

# Submission time Handle Problem Language Result Execution time Memory
34364 2017-11-10T18:07:43 Z bnahmad15 Potemkin cycle (CEOI15_indcyc) C++14
30 / 100
1000 ms 27428 KB
#include <bits/stdc++.h>
using namespace std;

int n,m,u,v;
bool is[1001][1001] = {false},vis[1001]={false};
vector <int> adj[1001];
vector <int> roads[1001][1001];
vector <int> taken;
void output(vector<int> &to){
	for (auto i : to){
		printf("%d ",i+1);
	}
	exit(0);
}
void DFS(int src,int node,int dis){
	if (roads[src][node].size() < 3){
		roads[src][node].push_back(dis);
	}
	if (vis[node])
		return;
	vis[node]=true;
	taken.push_back(node);
	if (dis >= 3 && is[node][src]){
		bool flag = true;
		for (int i = 0;i<taken.size();i++){
			for (int j = i+2;j<taken.size();j++){
				if (i==0&&j==taken.size()-1)
					continue;
				if (is[taken[i]][taken[j]]){
					flag = false;
					break;
				}
			}
			if (!flag)
				break;
		}
		if (flag){
			output(taken);
		}
	}
	for(auto i : adj[node]){
		DFS(src,i,dis+1);
	}
	taken.pop_back();
	vis[node]=false;
}

int main(){

	scanf("%d%d",&n,&m);
	for (int i = 0; i<m;i++){
		scanf("%d%d",&u,&v);
		u--,v--;
		adj[u].push_back(v);
		adj[v].push_back(u);
		is[u][v]=is[v][u]=true;
	}
	for (int i = 0 ; i < n;i++){
		memset(vis,false,sizeof vis);
		DFS(i,i,0);
	}
	puts("no");
	return 0;
}

Compilation message

indcyc.cpp: In function 'void DFS(int, int, int)':
indcyc.cpp:25:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0;i<taken.size();i++){
                   ^
indcyc.cpp:26:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int j = i+2;j<taken.size();j++){
                      ^
indcyc.cpp:27:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if (i==0&&j==taken.size()-1)
                ^
indcyc.cpp: In function 'int main()':
indcyc.cpp:50: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:52: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 3 ms 26504 KB Output is correct
2 Correct 3 ms 26504 KB Output is correct
3 Correct 3 ms 26504 KB Output is correct
4 Correct 3 ms 26504 KB Output is correct
5 Correct 3 ms 26504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 26504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 26504 KB Output is correct
2 Correct 3 ms 26504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1000 ms 26504 KB Execution timed out
# Verdict Execution time Memory Grader output
1 Execution timed out 1000 ms 26504 KB Execution timed out
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1000 ms 26636 KB Execution timed out
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1000 ms 26504 KB Execution timed out
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1000 ms 27032 KB Execution timed out
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1000 ms 26768 KB Execution timed out
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1000 ms 27428 KB Execution timed out
2 Halted 0 ms 0 KB -