답안 #121678

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
121678 2019-06-27T00:16:40 Z sofhiasouza Chase (CEOI17_chase) C++14
70 / 100
1337 ms 81096 KB
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long int ll;
 
const int maxn = 1e5+10;
 
int n, v, vet[maxn];
ll dp[maxn][110], soma[maxn];
 
vector < int > grafo[maxn];

ll dfs(int u, int val, int pai)
{
	if(val == 0) return 0;
	if(dp[u][val]) return dp[u][val];
 
	ll resp1 = 0, resp2 = 0, cont = 0;
	for(int i = 0 ; i < (int) grafo[u].size() ; i++)
	{
		int v = grafo[u][i];

		if(v == pai) continue;
 
		dp[u][val] = max({dp[u][val], dfs(v, val, u), dfs(v, val-1, u) + soma[v] - vet[u]});
	}
	return dp[u][val];
}
 
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
 
	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);
	}
	grafo[0].pb(1);

	for(int i = 1; i <= n; i++) {
		for(auto v : grafo[i]) {
			soma[i] += vet[v];
		}
	}

	ll resp = dfs(0, v, 0);
 
	if(n <= 1000)
	{
		for(int i = 2 ; i <= n ; i++)
		{
			for(int j = 0 ; j <= n ; j++)
				for(int k = 0 ; k <= v ; k++) dp[j][k] = 0;
					
			grafo[0][0] = i;
			resp = max(resp, dfs(0, v, 0));
		}
	}
 
	cout << resp << endl;
}

Compilation message

chase.cpp: In function 'll dfs(int, int, int)':
chase.cpp:18:5: warning: unused variable 'resp1' [-Wunused-variable]
  ll resp1 = 0, resp2 = 0, cont = 0;
     ^~~~~
chase.cpp:18:16: warning: unused variable 'resp2' [-Wunused-variable]
  ll resp1 = 0, resp2 = 0, cont = 0;
                ^~~~~
chase.cpp:18:27: warning: unused variable 'cont' [-Wunused-variable]
  ll resp1 = 0, resp2 = 0, cont = 0;
                           ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2688 KB Output is correct
2 Correct 4 ms 2688 KB Output is correct
3 Correct 4 ms 2688 KB Output is correct
4 Correct 4 ms 2688 KB Output is correct
5 Correct 4 ms 2688 KB Output is correct
6 Correct 3 ms 2688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2688 KB Output is correct
2 Correct 4 ms 2688 KB Output is correct
3 Correct 4 ms 2688 KB Output is correct
4 Correct 4 ms 2688 KB Output is correct
5 Correct 4 ms 2688 KB Output is correct
6 Correct 3 ms 2688 KB Output is correct
7 Correct 1337 ms 3712 KB Output is correct
8 Correct 89 ms 3704 KB Output is correct
9 Correct 75 ms 3704 KB Output is correct
10 Correct 337 ms 3676 KB Output is correct
11 Correct 296 ms 3656 KB Output is correct
12 Correct 233 ms 3664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 330 ms 56132 KB Output is correct
2 Correct 309 ms 56824 KB Output is correct
3 Correct 67 ms 9820 KB Output is correct
4 Correct 156 ms 79872 KB Output is correct
5 Correct 711 ms 81096 KB Output is correct
6 Correct 652 ms 81016 KB Output is correct
7 Correct 659 ms 80860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2688 KB Output is correct
2 Correct 4 ms 2688 KB Output is correct
3 Correct 4 ms 2688 KB Output is correct
4 Correct 4 ms 2688 KB Output is correct
5 Correct 4 ms 2688 KB Output is correct
6 Correct 3 ms 2688 KB Output is correct
7 Correct 1337 ms 3712 KB Output is correct
8 Correct 89 ms 3704 KB Output is correct
9 Correct 75 ms 3704 KB Output is correct
10 Correct 337 ms 3676 KB Output is correct
11 Correct 296 ms 3656 KB Output is correct
12 Correct 233 ms 3664 KB Output is correct
13 Correct 330 ms 56132 KB Output is correct
14 Correct 309 ms 56824 KB Output is correct
15 Correct 67 ms 9820 KB Output is correct
16 Correct 156 ms 79872 KB Output is correct
17 Correct 711 ms 81096 KB Output is correct
18 Correct 652 ms 81016 KB Output is correct
19 Correct 659 ms 80860 KB Output is correct
20 Incorrect 258 ms 80500 KB Output isn't correct
21 Halted 0 ms 0 KB -