답안 #199679

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
199679 2020-02-02T17:42:42 Z algorithm16 Chase (CEOI17_chase) C++14
30 / 100
212 ms 79992 KB
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long int llint;
vector <int> v[100005];
llint arr[100005],s[100005],dp[100005][105],n,v1;
void dfs(int x,int par) {
	for(int j=0;j<v[x].size();j++) {
		if(v[x][j]==par) continue;
		dfs(v[x][j],x);
	}
	for(int j=0;j<v[x].size();j++) {
		if(v[x][j]==par) continue;
		dp[x][0]=max(dp[x][0],dp[v[x][j]][0]);
		for(int i=1;i<=v1;i++) {
			dp[x][i]=max(dp[x][i],dp[v[x][j]][i]);
			dp[x][i]=max(dp[x][i],dp[v[x][j]][i-1]+s[x]-arr[par]);
		}
	}
}
int main()
{
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	//cin >> n >> v1;
	scanf("%d %d", &n, &v1);
	for(int i=0;i<n;i++) {
		//cin >> arr[i];
		scanf("%d", &arr[i]);
	}
	for(int i=0;i<n-1;i++) {
		int a,b;
		//cin >> a >> b;
		scanf("%d %d", &a, &b);
		v[a-1].push_back(b-1);
		v[b-1].push_back(a-1);
	}
	for(int i=0;i<n;i++) {
		for(int j=0;j<v[i].size();j++) {
			s[i]+=arr[v[i][j]];
		}
	}
	dfs(0,-1);
	//cout << dp[0][v1];
	printf("%lld", dp[0][v1]);
	return 0;
}

Compilation message

chase.cpp: In function 'void dfs(int, int)':
chase.cpp:9:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int j=0;j<v[x].size();j++) {
              ~^~~~~~~~~~~~
chase.cpp:13:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int j=0;j<v[x].size();j++) {
              ~^~~~~~~~~~~~
chase.cpp: In function 'int main()':
chase.cpp:27:24: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'llint* {aka long long int*}' [-Wformat=]
  scanf("%d %d", &n, &v1);
                 ~~     ^
chase.cpp:27:24: warning: format '%d' expects argument of type 'int*', but argument 3 has type 'llint* {aka long long int*}' [-Wformat=]
chase.cpp:30:22: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'llint* {aka long long int*}' [-Wformat=]
   scanf("%d", &arr[i]);
               ~~~~~~~^
chase.cpp:40:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=0;j<v[i].size();j++) {
               ~^~~~~~~~~~~~
chase.cpp:27:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &v1);
  ~~~~~^~~~~~~~~~~~~~~~~~
chase.cpp:30:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &arr[i]);
   ~~~~~^~~~~~~~~~~~~~~
chase.cpp:35:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &a, &b);
   ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 2680 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 2680 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 143 ms 52472 KB Output is correct
2 Correct 158 ms 52476 KB Output is correct
3 Correct 94 ms 10080 KB Output is correct
4 Correct 157 ms 77688 KB Output is correct
5 Correct 212 ms 79992 KB Output is correct
6 Correct 189 ms 79992 KB Output is correct
7 Correct 191 ms 79608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 2680 KB Output isn't correct
2 Halted 0 ms 0 KB -