Submission #349591

#TimeUsernameProblemLanguageResultExecution timeMemory
349591shrek12357Chase (CEOI17_chase)C++14
0 / 100
47 ms2660 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...