Submission #349591

# Submission time Handle Problem Language Result Execution time Memory
349591 2021-01-17T22:02:10 Z shrek12357 Chase (CEOI17_chase) C++14
0 / 100
47 ms 2660 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <climits>
#include <cmath>
#include <fstream>
#include <queue>
#include <stack>
#include <iomanip>
#include <bitset>
//#include "network.h"
using namespace std;
#define ll long long
//cin.tie(0);ios_base::sync_with_stdio(0);

const int MAXN = 1005;

ll ans = 0;

vector<int> nums;
vector<int> adjList[MAXN];
int n, m;

void dfs(int src, int par, int v, ll tot) {
	ans = max(ans, tot);
	if (v == 0) {
		return;
	}
	for (auto i : adjList[src]) {
		if (i == par) {
			continue;
		}
		tot += nums[i];
	}
	for (auto i : adjList[src]) {
		if (i == par) {
			continue;
		}
		dfs(i, src, v - 1, tot);
	}
}

int main() {

	cin >> n >> m;

	for (int i = 0; i < n; i++) {
		ll temp;
		cin >> temp;
		nums.push_back(temp);
	}
	for (int i = 0; i < n - 1; i++) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		adjList[a].push_back(b);
		adjList[b].push_back(a);
	}
	for (int i = 0; i < n; i++) {
		dfs(i, -1, m, 0);
	}
	cout << ans << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 47 ms 2660 KB Execution killed with signal 6 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -