Submission #50100

# Submission time Handle Problem Language Result Execution time Memory
50100 2018-06-07T14:13:04 Z radoslav11 Potemkin cycle (CEOI15_indcyc) C++14
70 / 100
1000 ms 2540 KB
#include <bits/stdc++.h>
#define endl '\n'
 
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
 
using namespace std;
template<class T, class T2> inline int chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline int chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const int MAXN = (1 << 10);
 
int n, m;
vector<int> adj[MAXN];
bool has[MAXN][MAXN];
 
void read()
{
	cin >> n >> m;
	for(int i = 0; i < m; i++)
	{
		int u, v;
		cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	
		has[u][v] = 1;
		has[v][u] = 1;
	}
}
 
struct dsu
{
	int sz;
	vector<int> par, psz;
 
	void init(int n)
	{
		sz = n;
		par.assign(sz + 1, 0);
		psz.assign(sz + 1, 0);
		for(int i = 0; i <= sz; i++)
			par[i] = i, psz[i] = 1;
	}
 
	int root(int u) { return par[u] = ((u == par[u]) ? u : root(par[u])); }
	
	bool connected(int x, int y) { return root(x) == root(y); }
 
	void unite(int x, int y)
	{
		x = root(x), y = root(y);
		if(x == y) return;
		if(psz[x] > psz[y]) swap(x, y);
		par[x] = y, psz[y] += psz[x]; 
	}
};
 
dsu d;
bool used[MAXN];
 
void dfs(int u)
{
	used[u] = 1;
	for(int v: adj[u])
		if(!used[v])
		{
			dfs(v);
			d.unite(u, v);
		}
}
 
bool rhas[MAXN];
int par[MAXN];
 
void solve(int rt, int l, int r)
{
	queue<int> q;
	memset(par, -1, sizeof(par));
	
	q.push(l);
	par[l] = rt;
	par[rt] = 0;
	
	while(!q.empty())
	{
		int u = q.front();
		q.pop();
 
		for(int v: adj[u])
			if(par[v] == -1 && (!rhas[v] || v == r))
			{
				q.push(v);
				par[v] = u;
			}
	}
 
	if(par[r] == -1) return;
 
	int x = r;
	while(x)
	{
		cout << x << " ";
		x = par[x];
	}
 
	cout << endl;
	exit(0);
}
 
void solve()
{
	for(int root = 1; root <= n; root++)
	{
		d.init(n);
		for(int i = 1; i <= n; i++) used[i] = 0, rhas[i] = 0;
 
		used[root] = 1;
		for(int v: adj[root])
			rhas[v] = 1, dfs(v);		
 
		for(int v: adj[root])
			for(int u: adj[root])
				if(v < u && u < root && !has[u][v] && d.root(u) == d.root(v))
					solve(root, u, v);
	}
 
	cout << "no" << endl; 
}
 
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
 
	read();
	solve();
	return 0;
}
 
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 420 KB Output is correct
3 Correct 2 ms 556 KB Output is correct
4 Correct 2 ms 612 KB Output is correct
5 Correct 2 ms 612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 612 KB Output is correct
2 Correct 2 ms 612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 800 KB Output is correct
2 Correct 6 ms 800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 1004 KB Output is correct
2 Correct 4 ms 1004 KB Output is correct
3 Correct 20 ms 1004 KB Output is correct
4 Correct 44 ms 1004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 1004 KB Output is correct
2 Correct 52 ms 1004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 2236 KB Output is correct
2 Correct 15 ms 2236 KB Output is correct
3 Execution timed out 1087 ms 2284 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1088 ms 2284 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 405 ms 2284 KB Output is correct
2 Correct 540 ms 2284 KB Output is correct
3 Correct 452 ms 2540 KB Output is correct
4 Execution timed out 1078 ms 2540 KB Time limit exceeded