# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
905947 | Trisanu_Das | Harbingers (CEOI09_harbingers) | C++17 | 12 ms | 892 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 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 time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |