Submission #162412

# Submission time Handle Problem Language Result Execution time Memory
162412 2019-11-08T07:34:39 Z MvC Railway (BOI17_railway) C++11
0 / 100
99 ms 24660 KB
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.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<<62);
const int inf=(1<<30);
const int nmax=1e5+50;
const int mod=1e9+7;
using namespace std;
int n,m,k,i,x,y,in[nmax],out[nmax],tin,up[nmax][20],mn,mx,ed[nmax],rs,id[nmax],vl[nmax],lc;
vector<pair<int,int> >a[nmax];
vector<int>vc;
bitset<nmax>on;
void dfs(int x,int p)
{
	in[x]=++tin;
	id[tin]=x;
	up[x][0]=p;
	for(int i=1;i<19;i++)up[x][i]=up[up[x][i-1]][i-1];
	for(int i=0;i<(int)a[x].size();i++)
	{
		int y=a[x][i].fr;
		if(y==p)continue;
		dfs(y,x);
	}
	out[x]=++tin;
}
int anc(int x,int y)
{
	return in[x]<=in[y] && out[y]<=out[x];
}
int lca(int x,int y)
{
	if(anc(x,y))return x;
	if(anc(y,x))return y;
	for(int i=18;i>=0;i--)if(!anc(up[x][i],y))x=up[x][i];
	return up[x][0];
}
void sol(int x,int p,int e)
{
	for(int i=0;i<(int)a[x].size();i++)
	{
		int y=a[x][i].fr;
		if(y==p)continue;
		sol(y,x,a[x][i].sc);
		vl[x]+=vl[y];
	}
	if(vl[x]>=k)vc.pb(e);
}
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>>k;
	for(i=1;i<n;i++)
	{
		cin>>x>>y;
		a[x].pb(mkp(y,i));
		a[y].pb(mkp(x,i));
	}
	dfs(1,1);
	while(m--)
	{
		cin>>x;
		lc=-1;
		for(i=1;i<=x;i++)
		{
			cin>>y;
			vl[y]++;
			if(lc==-1)lc=y;
			else lc=lca(lc,y);
		}
		vl[lc]-=2;
	}
	sol(1,1,0);
	cout<<(int)vc.size()<<endl;
	for(i=0;i<(int)vc.size();i++)cout<<vc[i]<<" ";
	cout<<endl;
	return 0;
}

Compilation message

railway.cpp:2:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization("O3")
 
railway.cpp:3:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization("unroll-loops")
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 2744 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 2744 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 91 ms 24660 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 99 ms 20728 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 99 ms 20728 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 2744 KB Output isn't correct
2 Halted 0 ms 0 KB -