제출 #61780

#제출 시각아이디문제언어결과실행 시간메모리
61780IvanCChase (CEOI17_chase)C++17
70 / 100
369 ms104840 KiB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int MAXN = 1e5 + 10;
const int MAXC = 1e2 + 5;

vector<int> grafo[MAXN];
ll dp[MAXN][MAXC],P[MAXN],somatorio[MAXN],best;
int N,C;

void dfs(int v,int p){
	
	somatorio[v] = 0;
	for(int i = 0;i<=C;i++) dp[v][i] = 0;

	for(int u : grafo[v]){
		if(u == p) continue;
		dfs(u,v);
		somatorio[v] += P[u];
	}

	for(int u : grafo[v]){
		if(u == p) continue;
		for(int i = 1;i<=C;i++){
			dp[v][i] = max(dp[v][i], max(dp[u][i], dp[u][i-1] + somatorio[v] ) );
		}
	}

}

int main(){

	scanf("%d %d",&N,&C);
	for(int i = 1;i<=N;i++){
		scanf("%lld",&P[i]);
	}
	for(int i = 1;i<N;i++){
		int u,v;
		scanf("%d %d",&u,&v);
		grafo[u].push_back(v);
		grafo[v].push_back(u);
	}

	int limite = N;
	if(N > 1000) limite = 1;

	for(int i = 1;i<=limite;i++){
		dfs(i,-1);
		for(int j = 0;j<=C;j++) best = max(best,dp[i][j]);
	}

	printf("%lld\n",best);

	return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

chase.cpp: In function 'int main()':
chase.cpp:35:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d",&N,&C);
  ~~~~~^~~~~~~~~~~~~~~
chase.cpp:37:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld",&P[i]);
   ~~~~~^~~~~~~~~~~~~~
chase.cpp:41:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&u,&v);
   ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...