Submission #1030880

#TimeUsernameProblemLanguageResultExecution timeMemory
1030880UnforgettableplSecurity Guard (JOI23_guard)C++17
37 / 100
775 ms1048576 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int n,m,q; cin >> n >> m >> q; vector<int> arr(n+1); for(int i=1;i<=n;i++)cin>>arr[i]; vector<vector<int>> adj(n+1); for(int i=1;i<n;i++){ int a,b; cin >> a >> b; adj[a].emplace_back(b); adj[b].emplace_back(a); } int ans = 0; int currmax = 0; function<void(int,int,int,int)> dfs = [&](int x,int p,int curr,int curroffset){ ans+=arr[p]; curr+=arr[p]; curr-=arr[x]; if(curr<0){ curroffset-=curr; currmax=max(currmax,curroffset); curr = 0; } for(int&i:adj[x])if(i!=p)dfs(i,x,curr,curroffset); }; dfs(1,0,arr[1],0); cout << ans+currmax << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...