This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "deliveries.h"
#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define fore(i,a,b) for(ll i=a,ioi=b;i<ioi;i++)
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define mset(a,v) memset((a),(v),sizeof(a))
#define imp(v) for(auto asd:v)cout<<asd<<" ";cout<<"\n"
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;
const ll MAXN=1e5+5;
ll n;
vector<ii>g[MAXN];
ll tot=1; //extra zero (return)
ll t[MAXN],c[MAXN];
ll res=0;
void dfs(ll x, ll f){
c[x]=t[x];
for(auto [y,w]:g[x])if(y!=f){
dfs(y,x);
res+=2*w*min(c[y],tot-c[y]);
c[x]+=c[y];
}
}
void init(int N, std::vector<int> u, std::vector<int> v, std::vector<int> w, std::vector<int> T) {
n=N;
fore(i,0,SZ(u)){
g[u[i]].pb({v[i],w[i]});
g[v[i]].pb({u[i],w[i]});
}
fore(i,0,n)t[i]=T[i],tot+=t[i];
}
long long max_time(int s, int x) {
tot+=-t[s]+x;
t[s]=x;
res=0;
dfs(0,-1);
return res;
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |