| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 860989 | 12345678 | Harbingers (CEOI09_harbingers) | C++17 | 69 ms | 17872 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll nx=1e5+5, inf=1e18;
ll n, ds[nx], lz[nx], sp[nx], ans[nx], u, v, w;
vector<pair<int, int>> d[nx];
bool querymode;
struct line
{
ll m, c;
mutable ll p;
line(ll m, ll c, ll p): m(m), c(c), p(p){}
bool operator< (const line &o) const {return querymode?p<o.p:m>o.m;}
};
struct convexhull:multiset<line>
{
ll div(ll a, ll b)
{
if (a%b==0||(a^b)>=0) return a/b;
return a/b-1;
}
bool isect(iterator x, iterator y)
{
if (y==end()) return x->p=inf, false;
if (x->m==y->m) x->p=x->m>=y->m?-inf:inf;
else x->p=div(y->c-x->c, x->m-y->m);
return x->p>=y->p;
}
void add(ll m, ll c)
{
auto x=insert(line(m, c, 0)), y=next(x);
while (isect(x, y)) y=erase(y);
if ((y=x)!=begin()&&isect(--x, y)) isect(x, erase(y));
while ((y=x)!=begin()&&(--x)->p>=y->p) isect(x, erase(y));
}
ll query(ll x)
{
querymode=1;
auto itr=lower_bound(line(0, 0, x));
querymode=0;
return itr->m*x+itr->c;
}
} s;
void pre(int u, int p)
{
for (auto [v, w]:d[u]) if (v!=p) ds[v]=ds[u]+w, pre(v, u);
}
void dfs(int u, int p)
{
if (u!=1) ans[u]=lz[u]+ds[u]*sp[u]+s.query(sp[u]);
s.add(-ds[u], ans[u]);
for (auto [v, w]:d[u]) if (v!=p) dfs(v, u);
}
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n;
for (int i=0; i<n-1; i++) cin>>u>>v>>w, d[u].push_back({v, w}), d[v].push_back({u, w});
for (int i=2; i<=n; i++) cin>>lz[i]>>sp[i];
pre(1, 1); dfs(1, 1);
for (int i=2; i<=n; i++) cout<<ans[i]<<'\n';
}
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
