# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
692273 | sudheerays123 | Harbingers (CEOI09_harbingers) | C++17 | 13 ms | 732 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;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long int
const ll N = 2500+5 , INF = 1e18 , MOD = 1e9+7;
vector<pair<ll,ll>> adj[N];
vector<ll> dist(N);
void dfs1(ll s , ll p){
for(auto u : adj[s]){
if(u.first == p) continue;
dist[u.first] = dist[s]+u.second;
dfs1(u.first,s);
}
}
vector<ll> path,dp(N,INF),w(N),speed(N);
void dfs2(ll s , ll p){
for(auto u : path) dp[s] = min(dp[s],w[s]+(dist[s]-dist[u])*speed[s] + dp[u]);
path.push_back(s);
for(auto u : adj[s]){
if(u.first == p) continue;
dfs2(u.first,s);
}
path.pop_back();
}
void solve(){
ll n;
cin >> n;
for(ll i = 1; i < n; i++){
ll a,b,c;
cin >> a >> b >> c;
adj[a].push_back(make_pair(b,c));
adj[b].push_back(make_pair(a,c));
}
for(ll i = 2; i <= n; i++) cin >> w[i] >> speed[i];
dist[1] = 0;
dfs1(1,0);
dp[1] = 0;
dfs2(1,0);
for(ll i = 2; i <= n; i++) cout << dp[i] << " ";
}
int main(){
fast;
ll tc = 1;
// cin >> tc;
while(tc--) solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |