제출 #692273

#제출 시각아이디문제언어결과실행 시간메모리
692273sudheerays123Harbingers (CEOI09_harbingers)C++17
20 / 100
13 ms732 KiB
#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 timeMemoryGrader output
Fetching results...