# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
147186 |
2019-08-28T10:49:59 Z |
MvC |
Chase (CEOI17_chase) |
C++11 |
|
197 ms |
94964 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;
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 |
5 ms |
2680 KB |
Output is correct |
2 |
Correct |
5 ms |
2680 KB |
Output is correct |
3 |
Correct |
5 ms |
2680 KB |
Output is correct |
4 |
Correct |
5 ms |
2680 KB |
Output is correct |
5 |
Incorrect |
5 ms |
2680 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
2680 KB |
Output is correct |
2 |
Correct |
5 ms |
2680 KB |
Output is correct |
3 |
Correct |
5 ms |
2680 KB |
Output is correct |
4 |
Correct |
5 ms |
2680 KB |
Output is correct |
5 |
Incorrect |
5 ms |
2680 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
182 ms |
94904 KB |
Output is correct |
2 |
Correct |
197 ms |
94964 KB |
Output is correct |
3 |
Correct |
134 ms |
92144 KB |
Output is correct |
4 |
Correct |
154 ms |
91740 KB |
Output is correct |
5 |
Correct |
187 ms |
91896 KB |
Output is correct |
6 |
Correct |
181 ms |
91712 KB |
Output is correct |
7 |
Correct |
195 ms |
91768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
2680 KB |
Output is correct |
2 |
Correct |
5 ms |
2680 KB |
Output is correct |
3 |
Correct |
5 ms |
2680 KB |
Output is correct |
4 |
Correct |
5 ms |
2680 KB |
Output is correct |
5 |
Incorrect |
5 ms |
2680 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |