Submission #475443

# Submission time Handle Problem Language Result Execution time Memory
475443 2021-09-22T13:13:31 Z MohamedAhmed04 Potemkin cycle (CEOI15_indcyc) C++14
20 / 100
19 ms 2084 KB
#include <bits/stdc++.h>

using namespace std ;

const int MAX = 1000 + 10 ;

int arr[MAX] ;
int n , m ;

vector< vector<int> >adj(MAX) ;

int vis[MAX] , dep[MAX] , P[MAX] ;

void dfs(int node , int Max)
{
	vis[node] = 1 ;
	int node2 = -1 ;
	for(auto &child : adj[node])
	{
		if(vis[child] && child != P[node])
		{
			if(dep[child] > dep[node])
				continue ;
			if(dep[child] > Max)
				Max = dep[child] , node2 = child ;
		}
	}
	if(node2 != -1 && dep[node] - dep[node2] + 1 >= 4)
	{
		while(node != node2)
		{
			cout<<node<<" " ;
			node = P[node] ;
		}
		cout<<node2<<"\n" ;
		exit(0) ;
	}
	for(auto &child : adj[node])
	{
		if(vis[child])
			continue ;
		P[child] = node , dep[child] = dep[node] + 1 ;
		dfs(child , Max) ;
	}
}

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>n>>m ;
	for(int i = 0 ; i < m ; ++i)
	{
		int x , y ;
		cin>>x>>y ;
		adj[x].push_back(y) ;
		adj[y].push_back(x) ;
	}
	for(int i = 1 ; i <= n ; ++i)
	{
		if(vis[i])
			continue ;
		dfs(i , -1) ;
	}
	return cout<<"no\n" , 0 ;
}		
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Expected integer, but "no" found
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Incorrect 1 ms 360 KB Expected integer, but "no" found
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 1228 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 716 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 1996 KB Output is correct
2 Correct 19 ms 2084 KB Output is correct
3 Incorrect 14 ms 1612 KB Expected integer, but "no" found
4 Halted 0 ms 0 KB -