Submission #68115

# Submission time Handle Problem Language Result Execution time Memory
68115 2018-08-16T00:51:28 Z thebes Dostavljač (COCI18_dostavljac) C++14
140 / 140
263 ms 4792 KB
#include <bits/stdc++.h>
using namespace std;

const int MN = 505;
typedef long long ll;
ll dp[MN][MN], en[MN][MN], arr[MN], N, T, i, j, k, x, y;
vector<int> adj[MN];
void solve(int n,int p){
	for(auto v : adj[n])
		if(v != p) solve(v, n);
	for(auto v : adj[n]){
		if(v == p) continue;
		for(k=T;k>=3;k--)
			for(j=1;j+2<=k;j++)
				en[n][k]=max(en[n][k],en[n][k-j-2]+dp[v][j]);
		for(k=T;k>=2;k--)
			for(j=1;j+1<=k;j++)
				en[n][k]=max(en[n][k],dp[n][k-j-1]+en[v][j]);
		for(k=T;k>=3;k--)
			for(j=1;j+2<=k;j++)
				dp[n][k]=max(dp[n][k],dp[n][k-j-2]+dp[v][j]);
	}
	for(j=T;j>=1;j--){
		en[n][j]=max(en[n][j],en[n][j-1]+arr[n]);
		dp[n][j]=max(dp[n][j],dp[n][j-1]+arr[n]);
	}
}
int main(){
	for(scanf("%lld%lld",&N,&T),i=1;i<=N;i++)
		scanf("%lld",&arr[i]);
	for(i=1;i<N;i++){
		scanf("%lld%lld",&x,&y);
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	solve(1, 0);
	printf("%lld\n",en[1][T]);
	return 0;
}

Compilation message

dostavljac.cpp: In function 'int main()':
dostavljac.cpp:29:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(scanf("%lld%lld",&N,&T),i=1;i<=N;i++)
      ~~~~~~~~~~~~~~~~~~~~~~~^~~~
dostavljac.cpp:30:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld",&arr[i]);
   ~~~~~^~~~~~~~~~~~~~~~
dostavljac.cpp:32:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld",&x,&y);
   ~~~~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 1368 KB Output is correct
2 Correct 6 ms 1368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1628 KB Output is correct
2 Correct 38 ms 1780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 2148 KB Output is correct
2 Correct 27 ms 2148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 3056 KB Output is correct
2 Correct 147 ms 3072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 131 ms 3804 KB Output is correct
2 Correct 61 ms 4008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 263 ms 4792 KB Output is correct
2 Correct 55 ms 4792 KB Output is correct