Submission #162489

# Submission time Handle Problem Language Result Execution time Memory
162489 2019-11-08T11:03:28 Z MvC Railway (BOI17_railway) C++11
36 / 100
129 ms 24176 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;
pair<int,int>c[nmax];
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=0;i<x;i++)
		{
			cin>>c[i].sc;
			c[i].fr=in[c[i].sc];
		}
		sort(c,c+x);
		for(i=0;i<x-1;i++)
		{
			vl[c[i].sc]++;
			vl[c[(i+1)%x].sc]++;
			vl[lca(c[i].sc,c[(i+1)%x].sc)]-=2;
		}
	}
	sol(1,1,0);
	sort(vc.begin(),vc.end());
	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 Correct 5 ms 2680 KB Output is correct
2 Incorrect 10 ms 4088 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2680 KB Output is correct
2 Incorrect 10 ms 4088 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 89 ms 23924 KB Output is correct
2 Correct 4 ms 2680 KB Output is correct
3 Correct 93 ms 23668 KB Output is correct
4 Correct 83 ms 23132 KB Output is correct
5 Correct 91 ms 24004 KB Output is correct
6 Correct 95 ms 24176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 97 ms 19960 KB Output is correct
2 Correct 122 ms 16728 KB Output is correct
3 Correct 113 ms 16264 KB Output is correct
4 Correct 111 ms 16248 KB Output is correct
5 Correct 111 ms 16248 KB Output is correct
6 Correct 96 ms 20216 KB Output is correct
7 Correct 102 ms 20112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 97 ms 19960 KB Output is correct
2 Correct 122 ms 16728 KB Output is correct
3 Correct 113 ms 16264 KB Output is correct
4 Correct 111 ms 16248 KB Output is correct
5 Correct 111 ms 16248 KB Output is correct
6 Correct 96 ms 20216 KB Output is correct
7 Correct 102 ms 20112 KB Output is correct
8 Incorrect 129 ms 20188 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2680 KB Output is correct
2 Incorrect 10 ms 4088 KB Output isn't correct
3 Halted 0 ms 0 KB -