제출 #156616

#제출 시각아이디문제언어결과실행 시간메모리
156616karmaHarbingers (CEOI09_harbingers)C++14
0 / 100
249 ms40740 KiB
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define FileName "test" #define ll long long #define ld long double #define pb emplace_back #define fi first #define se second using namespace std; using namespace __gnu_pbds; typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ord_set; typedef pair<int, int> pii; typedef pair<ll, int> plli; const int N = int(1e5) + 2; int in[N], n, out[N], Time = 0, r[N]; ll d[N], f[N], vantoc[N], chuanbi[N]; vector<pii> a[N]; struct line { ll a, b; line (ll a = 0, ll b = 0): a(a), b(b) {} ll GetVal(int x) {return a * vantoc[r[x]] + b;} }; struct TSegment { int l, r, mid; line cur; TSegment* left; TSegment* right; TSegment (int l = 0, int r = 0): l(l), r(r) { mid = (l + r) >> 1; cur = line(); if(l == r) { left = right = NULL; return; } left = new TSegment(l, mid); right = new TSegment(mid + 1, r); } void Update(int x, int y, line val) { if(l > y || r < x) return; if(x <= l && r <= y) { ll lcur = cur.GetVal(l); ll rcur = cur.GetVal(r); ll lval = val.GetVal(l); ll rval = val.GetVal(r); if(lcur >= lval && rcur >= rval) {cur = val; return;} if(lcur <= lval && rcur <= rval) return; ll mval = val.GetVal(mid); ll mcur = cur.GetVal(mid); if(lcur >= lval && mcur >= mval) { right -> Update(x, y, cur); cur = val; return; } if(lcur <= lval && mcur <= mval) { right -> Update(x, y, val); return; } if(mcur >= mval && rcur >= rval) { left -> Update(x, y, cur); cur = val; return; } if(mcur <= mval && rcur <= rval) { left -> Update(x, y, val); return; } } left -> Update(x, y, val); right -> Update(x, y, val); } ll Query(int x) { if(l > x || r < x) return 0; ll res = cur.GetVal(x); if(l == r) return res; res = min(res, left -> Query(x)); res = min(res, right -> Query(x)); return res; } } Min; void DFS(int u, int par) { r[in[u] = ++Time] = u; for(pii p: a[u]) { if(par == p.fi) continue; d[p.fi] = d[u] + p.se; DFS(p.fi, u); } out[u] = Time; } void GetAns(int u, int par) { ///f[v] = -d[u] * vantoc[v] + f[u] + chuanbi[v] + d[v] * vantoc[v]; if(u != 1) { f[u] = Min.Query(in[u]) + d[u] * vantoc[u] + chuanbi[u]; Min.Update(in[u], out[u], line(-d[u], f[u])); } for(pii p: a[u]) { if(par == p.fi) continue; GetAns(p.fi, u); } } void Enter() { cin >> n; int u, v, l; for(int i = 1; i < n; ++i) { cin >> u >> v >> l; a[u].pb(v, l), a[v].pb(u, l); } for(int i = 2; i <= n; ++i) cin >> chuanbi[i] >> vantoc[i]; DFS(1, 1); Min = TSegment(1, n); GetAns(1, 1); for(int i = 2; i <= n; ++i) cout << f[i] << ' '; } void Solve() { } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if(fopen(FileName".inp", "r")) { freopen(FileName".inp", "r", stdin); freopen(FileName".out", "w", stdout); } Enter(), Solve(); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

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