Submission #975086

#TimeUsernameProblemLanguageResultExecution timeMemory
9750868pete8Security Guard (JOI23_guard)C++17
37 / 100
124 ms23076 KiB
#include<iostream> #include<stack> #include<map> #include<vector> #include<string> #include<unordered_map> #include <queue> #include<cstring> #include<limits.h> #include <cassert> #include<cmath> #include<set> #include<algorithm> #include <iomanip> #include<numeric> //gcd(a,b) #include<bitset> #include <cstdlib> #include <cstdint> using namespace std; #define ll long long #define f first //#define endl "\n" #define s second #define pii pair<int,int> #define ppii pair<int,pii> #define vi vector<int> #define pb push_back #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define F(n) for(int i=0;i<n;i++) #define lb lower_bound #define ub upper_bound #define fastio ios::sync_with_stdio(false);cin.tie(NULL); #pragma GCC optimize ("03,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") using namespace std; #define int long long #define double long double const int mxn=2e5,inf=1e18,minf=-1e18; int val[mxn+10],ans=0; vector<int>adj[mxn+10]; void dfs(int cur,int p){ ans+=(val[cur]*(adj[cur].size()-(!!p))); for(auto i:adj[cur])if(i!=p)dfs(i,cur); } int32_t main(){ fastio int n,m,q;cin>>n>>m>>q; if(m!=n-1||q!=0)return 0; for(int i=1;i<=n;i++)cin>>val[i]; for(int i=0;i<n-1;i++){ int a,b;cin>>a>>b; adj[a].pb(b); adj[b].pb(a); } pair<pii,int> st={{minf,0},-1}; for(int i=1;i<=n;i++)st=max(st,{{val[i],-adj[i].size()},i}); dfs(st.s,0); cout<<ans; return 0; } /* */
#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...