Submission #147059

# Submission time Handle Problem Language Result Execution time Memory
147059 2019-08-27T10:57:48 Z MvC Potemkin cycle (CEOI15_indcyc) C++11
100 / 100
374 ms 1552 KB
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include<bits/stdc++.h>
//#include "boxes.h"
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<61);
const int inf=(1<<30);
const int nmax=1e3+50;
const int mod=1e9+7;
using namespace std;
int n,m,i,j,t,x,y,s,f,pr[nmax];
bitset<nmax>vz,vv,b[nmax],r[nmax];
vector<int>a[nmax],vc,vcc;
queue<int>q;
void dfs(int x,int p)
{
	vz[x]=1;
	vcc.pb(x);
	for(int i=0;i<a[x].size();i++)
	{
		int y=a[x][i];
		if(vz[y])continue;
		if(b[p][y])
		{
			if(!vv[y])
			{
				vc.pb(y);
				if(!s && (r[y]&vv).any())s=y;
			}
			vv[y]=1;
			continue;
		}
		dfs(y,p);
	}
}
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	cin>>n>>m;
	while(m--)
	{
		cin>>x>>y;
		b[x][y]=b[y][x]=1;
		a[x].pb(y);
		a[y].pb(x);
	}
	for(i=1;i<=n;i++)
	{
		b[i].flip();
		r[i]=b[i];
		r[i][0]=r[i][i]=0;
		b[i].flip();
	}
	for(i=1;i<=n;i++)
	{
		vz.reset();
		for(j=1;j<=n;j++)
		{
			if(b[i][j] || j==i || vz[j])continue;
			dfs(j,i);
			if(s)
			{
				m=i;
				for(t=1;t<=n;t++)
				{
					if(r[s][t] && vv[t])
					{
						f=t;
						break;
					}
				}
				break;
			}
			else
			{
				for(t=0;t<vc.size();t++)vv[vc[t]]=0;
				vc.clear();
				vv.reset();
				vcc.clear();
			}
		}
		if(s)break;
	}
	if(!s)rc("no");
	vv.reset(),vz.reset();
	for(i=0;i<vcc.size();i++)vv[vcc[i]]=1;
	q.push(s);
	vz[s]=vz[m]=1;
	pr[s]=m;
	while(!q.empty())
	{
		x=q.front();
		q.pop();
		for(i=0;i<a[x].size();i++)
		{
			y=a[x][i];
			if(vz[y] || (b[m][y] && y!=f))continue;
			vz[y]=1;
			pr[y]=x;
			if(y==f)break;
			q.push(y);
		}
		if(pr[f])break;
	}
	while(f)
	{
		cout<<f<<" ";
		f=pr[f];
	}
	cout<<endl;
	return 0;
}

Compilation message

indcyc.cpp:2:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization("O3")
 
indcyc.cpp:3:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization("unroll-loops")
 
indcyc.cpp: In function 'void dfs(int, int)':
indcyc.cpp:30:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<a[x].size();i++)
              ~^~~~~~~~~~~~
indcyc.cpp: In function 'int main()':
indcyc.cpp:90:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(t=0;t<vc.size();t++)vv[vc[t]]=0;
             ~^~~~~~~~~~
indcyc.cpp:100:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(i=0;i<vcc.size();i++)vv[vcc[i]]=1;
          ~^~~~~~~~~~~
indcyc.cpp:108:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(i=0;i<a[x].size();i++)
           ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 4 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 504 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
3 Correct 4 ms 636 KB Output is correct
4 Correct 16 ms 612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 504 KB Output is correct
2 Correct 15 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 1392 KB Output is correct
2 Correct 9 ms 1144 KB Output is correct
3 Correct 303 ms 1468 KB Output is correct
4 Correct 164 ms 1144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 888 KB Output is correct
2 Correct 235 ms 888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 1400 KB Output is correct
2 Correct 24 ms 1528 KB Output is correct
3 Correct 27 ms 1552 KB Output is correct
4 Correct 374 ms 1528 KB Output is correct