답안 #122558

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
122558 2019-06-28T15:34:39 Z sofhiasouza Chase (CEOI17_chase) C++14
30 / 100
279 ms 82168 KB
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long int ll;

const int maxn = 1e5+10;

vector < int > grafo[maxn];

int n, v, vet[maxn];
ll soma[maxn], dp[maxn][110];

void dfs(int u, int pai)
{
	for(int i = 0 ; i < grafo[u].size() ; i++)
	{
		int k = grafo[u][i];
		if(k == pai) continue;

		dfs(k, u);
		for(int j = 1 ; j <= v ; j++)
		{
			dp[u][j] = max({dp[u][j], dp[k][j-1] + soma[k] - vet[u], dp[k][j]});
		}
	}
}

int main()
{
	cin >> n >> v;

	for(int i = 1 ; i <= n ; i++) cin >> vet[i];

	for(int i = 0 ; i < n-1 ; i++)
	{
		int a, b;

		cin >> a >> b;

		grafo[a].pb(b);
		grafo[b].pb(a);
	}

	for(int i = 1 ; i <= n ; i++)
	{
		for(int j = 0 ; j < grafo[i].size() ; j++)
		{
			soma[i] += vet[grafo[i][j]];
		}
	}

	grafo[0].pb(1);

	dfs(0, 0);

	cout << dp[0][v] << endl;
}

Compilation message

chase.cpp: In function 'void dfs(int, int)':
chase.cpp:15:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0 ; i < grafo[u].size() ; i++)
                  ~~^~~~~~~~~~~~~~~~~
chase.cpp: In function 'int main()':
chase.cpp:46:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j = 0 ; j < grafo[i].size() ; j++)
                   ~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 2688 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 2688 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 249 ms 54136 KB Output is correct
2 Correct 242 ms 56184 KB Output is correct
3 Correct 140 ms 9712 KB Output is correct
4 Correct 222 ms 79872 KB Output is correct
5 Correct 268 ms 82168 KB Output is correct
6 Correct 279 ms 82084 KB Output is correct
7 Correct 264 ms 82012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 2688 KB Output isn't correct
2 Halted 0 ms 0 KB -