Submission #608643

#TimeUsernameProblemLanguageResultExecution timeMemory
608643Do_you_copyHarbingers (CEOI09_harbingers)C++17
100 / 100
164 ms21948 KiB
#include <bits/stdc++.h> #define taskname "test" #define fi first #define se second #define pb push_back #define faster ios_base::sync_with_stdio(0); cin.tie(0); using namespace std; using ll = long long; using ull = unsigned ll; using ld = long double; using pii = pair <ll, ll>; using pil = pair <ll, ll>; using pli = pair <ll, ll>; using pll = pair <ll, ll>; mt19937 Rand(chrono::steady_clock::now().time_since_epoch().count()); ll min(const ll &a, const ll &b){ return (a < b) ? a : b; } ll max(const ll &a, const ll &b){ return (a > b) ? a : b; } //const ll Mod = 1000000007; //const ll Mod2 = 999999999989; //only use when required const ll maxN = 1e5 + 1; ll n; vector <pii> adj[maxN]; ll s[maxN], v[maxN]; pll cht[maxN]; ll sz = 0; ll dp[maxN]; inline ld llersect(pll l, pll r){ return ld(r.se - l.se) / ld(l.fi - r.fi); } ll get(ll x){ ll l = 0, r = sz - 1; while (l < r){ ll mid = (l + r) / 2; if (llersect(cht[mid], cht[mid + 1]) < x) l = mid + 1; else r = mid; } return cht[l].fi * x + cht[l].se; } ll update(pll line){ if (sz < 2 || llersect(line, cht[sz - 1]) >= llersect(cht[sz - 1], cht[sz - 2])){ return sz; } ll l = 1, r = sz - 1; while (l < r){ ll mid = (l + r) / 2; if (llersect(line, cht[mid]) < llersect(cht[mid], cht[mid - 1])) r = mid; else l = mid + 1; } return l; } void dfs(ll u, ll p, ll dis = 0){ ll pre_size, pre_pos; pll pre_line; if (u == 1){ cht[sz++] = {0, 0}; } else{ dp[u] = get(v[u]) + dis * v[u] + s[u]; pll line = {-dis, dp[u]}; pre_size = sz; pre_pos = sz = update(line); pre_line = cht[pre_pos]; cht[sz++] = line; } for (const auto &i: adj[u]){ if (i.fi == p) continue; dfs(i.fi, u, i.se + dis); } if (u != 1){ sz = pre_size; cht[pre_pos] = pre_line; } } void Init(){ cin >> n; for (ll i = 1; i < n; ++i){ ll u, v, w; cin >> u >> v >> w; adj[v].pb({u, w}); adj[u].pb({v, w}); } for (ll i = 2; i <= n; ++i){ cin >> s[i] >> v[i]; } dfs(1, 0); for (ll i = 2; i <= n; ++i) cout << dp[i] << " "; } signed main(){ if (fopen(taskname".inp", "r")){ freopen(taskname".inp", "r", stdin); //freopen(taskname".out", "w", stdout); } faster; ll tt = 1; //cin >> tt; while (tt--){ Init(); } }

Compilation message (stderr)

harbingers.cpp: In function 'int main()':
harbingers.cpp:106:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  106 |         freopen(taskname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...