Submission #905947

#TimeUsernameProblemLanguageResultExecution timeMemory
905947Trisanu_DasHarbingers (CEOI09_harbingers)C++17
20 / 100
12 ms892 KiB
#include<bits/stdc++.h> using namespace std; #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(); } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); 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] << ' '; }
#Verdict Execution timeMemoryGrader output
Fetching results...