Submission #147193

# Submission time Handle Problem Language Result Execution time Memory
147193 2019-08-28T11:09:12 Z MvC Chase (CEOI17_chase) C++11
0 / 100
187 ms 95656 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=1e5+50;
const int mod=1e9+7;
using namespace std;
int n,i,x,y,k;
ll f[nmax][105],c[nmax],ch[nmax],mx;
vector<int>a[nmax];
void pre(int x,int p)
{
	ch[x]=0;
	for(int i=0;i<a[x].size();i++)
	{
		int y=a[x][i];
		if(y==p)continue;
		pre(y,x);
		ch[x]+=c[y];
	}
}
void dfs(int x,int p)
{
	if(x==p)
	{
		for(int i=0;i<=k;i++)f[x][i]=0;
		f[x][1]=ch[x];
		mx=max(mx,f[x][1]);
	}
	else
	{
		for(int i=0;i<=k;i++)
		{
			f[x][i]=0;
			if(!i)f[x][i]=f[p][i];
			else
			{
				f[x][i]=max(f[p][i-1]+ch[x],f[p][i]);
			}
			mx=max(mx,f[x][i]);
		}
	}
	for(int i=0;i<a[x].size();i++)
	{
		int y=a[x][i];
		if(y==p)continue;
		dfs(y,x);
	}
}
void dfs1(int x,int p)
{
	for(int i=0;i<a[x].size();i++)
	{
		int y=a[x][i];
		if(y==p)continue;
		dfs1(y,x);
		for(int j=0;j<=k;j++)
		{
			f[x][j]=0;
			if(!j)f[x][j]=f[y][j];
			else
			{
				f[x][j]=max(f[y][j-1]+ch[x],f[y][j]);
			}
			mx=max(mx,f[x][j]);
		}
	}
	if(a[x].size()==1 && x!=p)
	{
		for(int i=0;i<=k;i++)f[x][i]=0;
	}
}
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>>k;
	if(!k)rc(0);
	for(i=1;i<=n;i++)cin>>c[i];
	for(i=1;i<n;i++)
	{
		cin>>x>>y;
		a[x].pb(y);
		a[y].pb(x);
	}
	if(n<=1000)
	{
		for(i=1;i<=n;i++)
		{
			pre(i,i);
			dfs1(i,i);
		}
	}
	else
	{
		pre(1,1);
		dfs1(1,1);
	}
	cout<<mx<<endl;
	return 0;
}

Compilation message

chase.cpp:2:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization("O3")
 
chase.cpp:3:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization("unroll-loops")
 
chase.cpp: In function 'void pre(int, int)':
chase.cpp:28:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<a[x].size();i++)
              ~^~~~~~~~~~~~
chase.cpp: In function 'void dfs(int, int)':
chase.cpp:57:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<a[x].size();i++)
              ~^~~~~~~~~~~~
chase.cpp: In function 'void dfs1(int, int)':
chase.cpp:66:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<a[x].size();i++)
              ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 4 ms 2680 KB Output is correct
3 Correct 4 ms 2680 KB Output is correct
4 Incorrect 5 ms 2680 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 4 ms 2680 KB Output is correct
3 Correct 4 ms 2680 KB Output is correct
4 Incorrect 5 ms 2680 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 187 ms 95656 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 4 ms 2680 KB Output is correct
3 Correct 4 ms 2680 KB Output is correct
4 Incorrect 5 ms 2680 KB Output isn't correct
5 Halted 0 ms 0 KB -