제출 #705964

#제출 시각아이디문제언어결과실행 시간메모리
705964mychecksedadHarbingers (CEOI09_harbingers)C++17
0 / 100
1071 ms44744 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; ll w; }; struct Line{ bool type = false; double 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; vector<Edge> g[N]; ll s[N], c[N], dist[N], dp[N]; set<Line> cht; double intersection(const set<Line>::iterator &a, const set<Line>::iterator &b){ return (double) (a->c - b->c) / (b->m - a->m); } double intersection(const set<Line>::iterator &a, const Line &b){ return (double) (a->c - b.c) / (b.m - a->m); } void calcX(const set<Line>::iterator &a){ if(cht.size() > 1){ Line L = *a; L.x = intersection(prev(a), a); cht.insert(a, L); } } 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(cht.upper_bound({1, (double) 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(prev(prev(cht.end())), prev(cht.end())) <= intersection(prev(cht.end()), L)){ popp.pb(*prev(cht.end())); cht.erase(prev(cht.end())); } auto it = cht.insert(L).first; calcX(it); auto val = *it; dfs(u, v); cht.erase(val); for(auto &popped: popp) cht.insert(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.insert({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; }

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

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