이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define pb push_back
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define mp make_pair
const int maxn5 = 1e5 + 10;
const int ssq = 320;
const ll inf = 1e18;
ll h[maxn5], have[maxn5];
ll a[maxn5], lim, ans = 0;
vector <int> adj[maxn5];
inline void dfs(int v, int par){
for(auto u : adj[v]) if(u != par)
have[v] += a[u];
have[v] += a[v];
if(h[v] < lim)
ans = max(ans, have[v]);
for(auto u : adj[v]) if(u != par){
h[u] = h[v] + 1;
have[u] = have[v] - a[u];
dfs(u, v);
}
cout << v << ' ' << h[v] << ' ' << have[v] << endl;
return;
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int n; cin >> n >> lim;
for(int i = 0; i < n; i++)
cin >> a[i];
for(int i = 0; i < n - 1; i++){
int a, b; cin >> a >> b;
a--; b--;
adj[a].pb(b);
adj[b].pb(a);
}
dfs(0, -1);
cout << ans - a[0] << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |