Submission #705976

#TimeUsernameProblemLanguageResultExecution timeMemory
705976mychecksedadHarbingers (CEOI09_harbingers)C++17
0 / 100
258 ms37680 KiB
/* Author : Mychecksdead */ #include<bits/stdc++.h> using namespace std; typedef long long int ll; #define MOD (1000000000+7) #define MOD1 (998244353) #define PI 3.1415926535 #define pb push_back #define all(x) x.begin(), x.end() const int N = 1e5+100, M = 1e5+10, K = 20; struct Edge{ int to, w; }; struct Line{ bool type = false; float x = 0; ll m, c; bool operator < (const Line &other) const{ if(type != other.type) return x < other.x; return m < other.m; } }; int n, dist[N]; vector<Edge> g[N]; ll s[N], c[N], dp[N]; deque<Line> cht; float intersection(const Line &a, const Line &b){ return (float) (a.c - b.c) / (b.m - a.m); } void calcX(const deque<Line>::iterator &a){ if(cht.size() > 1){ a->x = intersection(*prev(a), *a); } } void pre(int v, int p){ for(auto U: g[v]){ int u = U.to; ll w = U.w; if(u != p){ dist[u] = dist[v] + w; pre(u, v); } } } void dfs(int v, int p){ for(auto U: g[v]){ int u = U.to; if(u != p){ vector<Line> popp; Line j = *prev(upper_bound(all(cht), Line{1, (float) s[v], 0, 0})); dp[u] = j.c + j.m * c[u] + s[u] + c[u] * dist[u]; Line L{0, 0, -dist[u], dp[u]}; while(cht.size() > 1 && intersection(cht[cht.size() - 2], cht.back()) >= intersection(cht.back(), L)){ popp.pb(cht.back()); cht.pop_back(); } cht.pb(L); calcX(prev(cht.end())); dfs(u, v); cht.pop_back(); reverse(all(popp)); for(auto &popped: popp) cht.pb(popped); } } } void solve(){ cin >> n; for(int i = 0; i < n - 1; ++i){ int u, v, w; cin >> u >> v >> w; g[u].pb({v, w}); g[v].pb({u, w}); } for(int i = 2; i <= n; ++i) cin >> s[i] >> c[i]; dist[1] = 0; pre(1, 0); dp[1] = 0; cht.pb({0, 0, 0, 0}); dfs(1, 0); for(int i = 2; i <= n; ++i) cout << dp[i] << ' '; } int main(){ cin.tie(0); ios::sync_with_stdio(0); int T = 1, aa; // cin >> T;aa=T; while(T--){ // cout << "Case #" << aa-T << ": "; solve(); cout << '\n'; } return 0; }

Compilation message (stderr)

harbingers.cpp: In function 'int main()':
harbingers.cpp:102:14: warning: unused variable 'aa' [-Wunused-variable]
  102 |   int T = 1, aa;
      |              ^~
#Verdict Execution timeMemoryGrader output
Fetching results...