Submission #1030883

#TimeUsernameProblemLanguageResultExecution timeMemory
1030883UnforgettableplSecurity Guard (JOI23_guard)C++17
37 / 100
803 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)> dfs = [&](int x,int p,int curr){ ans+=arr[p]; curr+=arr[p]; curr-=arr[x]; currmax=max(currmax,-curr); for(int&i:adj[x])if(i!=p)dfs(i,x,curr); }; dfs(1,0,arr[1]); 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...