Submission #147189

# Submission time Handle Problem Language Result Execution time Memory
147189 2019-08-28T10:59:02 Z MvC Chase (CEOI17_chase) C++11
70 / 100
232 ms 92764 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);
	}
}
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);
			dfs(i,i);
		}
	}
	else
	{
		pre(1,1);
		dfs(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++)
              ~^~~~~~~~~~~~
# 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 5 ms 2652 KB Output is correct
4 Correct 5 ms 2684 KB Output is correct
5 Correct 4 ms 2680 KB Output is correct
6 Correct 5 ms 2680 KB Output is correct
# 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 5 ms 2652 KB Output is correct
4 Correct 5 ms 2684 KB Output is correct
5 Correct 4 ms 2680 KB Output is correct
6 Correct 5 ms 2680 KB Output is correct
7 Correct 218 ms 3676 KB Output is correct
8 Correct 46 ms 3664 KB Output is correct
9 Correct 33 ms 3576 KB Output is correct
10 Correct 232 ms 3648 KB Output is correct
11 Correct 101 ms 3576 KB Output is correct
12 Correct 56 ms 3640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 173 ms 92764 KB Output is correct
2 Correct 178 ms 92728 KB Output is correct
3 Correct 131 ms 90016 KB Output is correct
4 Correct 157 ms 90324 KB Output is correct
5 Correct 188 ms 90320 KB Output is correct
6 Correct 192 ms 90280 KB Output is correct
7 Correct 205 ms 90364 KB Output is correct
# 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 5 ms 2652 KB Output is correct
4 Correct 5 ms 2684 KB Output is correct
5 Correct 4 ms 2680 KB Output is correct
6 Correct 5 ms 2680 KB Output is correct
7 Correct 218 ms 3676 KB Output is correct
8 Correct 46 ms 3664 KB Output is correct
9 Correct 33 ms 3576 KB Output is correct
10 Correct 232 ms 3648 KB Output is correct
11 Correct 101 ms 3576 KB Output is correct
12 Correct 56 ms 3640 KB Output is correct
13 Correct 173 ms 92764 KB Output is correct
14 Correct 178 ms 92728 KB Output is correct
15 Correct 131 ms 90016 KB Output is correct
16 Correct 157 ms 90324 KB Output is correct
17 Correct 188 ms 90320 KB Output is correct
18 Correct 192 ms 90280 KB Output is correct
19 Correct 205 ms 90364 KB Output is correct
20 Incorrect 192 ms 91796 KB Output isn't correct
21 Halted 0 ms 0 KB -