# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
937117 | amirhoseinfar1385 | Harbingers (CEOI09_harbingers) | C++17 | 4 ms | 6748 KiB |
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<bits/stdc++.h>
using namespace std;
const long long maxn=100000+10;
long long inf=1e18;
struct func{
long long fas,shib;
long long inersect(func f){
long long sor=fas-f.fas,makh=f.shib-shib;
if(makh==0){
if(sor>0){
return -inf;
}
return inf;
}
if(makh<0){
makh*=-1;
sor*=-1;
}
if(sor<0){
return sor/makh;
}
return (sor+makh-1)/makh;
}
};
struct yal{
long long u,v,w;
long long getad(long long fu){
return (u^v^fu);
}
}alle[maxn];
long long n,timea=0,high[maxn],para[maxn],dp[maxn];
pair<long long,long long>stf[maxn],all[maxn];
vector<long long>adj[maxn];
void dfs(long long u,long long par=0,long long len=0){
timea++;
para[u]=par;
high[u]=len;
stf[u].first=timea;
for(auto x:adj[u]){
long long v=alle[x].getad(u);
if(v!=par){
dfs(v,u,len+alle[x].w);
}
}
stf[u].second=timea;
}
void vorod(){
cin>>n;
for(long long i=0;i<n-1;i++){
cin>>alle[i].u>>alle[i].v>>alle[i].w;
adj[alle[i].u].push_back(i);
adj[alle[i].v].push_back(i);
}
for(long long i=2;i<=n;i++){
cin>>all[i].first>>all[i].second;
}
}
void pre(){
dfs(1);
}
void upd(long long u){
dp[u]=high[u]*all[u].second;
long long fu=para[u];
while(fu!=0){
dp[u]=min(dp[u],dp[fu]+all[u].second*high[u]-all[u].second*high[fu]);
fu=para[fu];
}
dp[u]+=all[u].first;
}
void solve(long long u=1){
upd(u);
for(auto x:adj[u]){
long long v=alle[x].getad(u);
if(v!=para[u]){
solve(v);
}
}
}
void khor(){
for(long long i=2;i<=n;i++){
cout<<dp[i]<<" ";
}
cout<<"\n";
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
freopen("inp.txt","r",stdin);
vorod();
pre();
solve();
khor();
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |