QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#406613 | #6660. 택시 여행 | hotboy2703 | 0 | 0ms | 0kb | C++14 | 3.7kb | 2024-05-07 15:16:11 | 2024-05-07 15:16:11 |
answer
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define BIT(mask,i) (((mask) >> (i))&1LL)
#define MASK(i) (1LL << (i))
#define MP make_pair
#define pll pair <ll,ll>
#define fi first
#define se second
#define sz(a) (ll((a).size()))
const ll INF = 3e18;
struct Line {
mutable ll k, m, p;
bool operator<(const Line& o) const { return k < o.k; }
bool operator<(ll x) const { return p < x; }
};
struct LineContainer : multiset<Line, less<>> {
// (for doubles, use inf = 1/.0, div(a,b) = a/b)
static const ll inf = LLONG_MAX;
ll div(ll a, ll b) { // floored division
return a / b - ((a ^ b) < 0 && a % b); }
bool isect(iterator x, iterator y) {
if (y == end()) return x->p = inf, 0;
if (x->k == y->k) x->p = x->m > y->m ? inf : -inf;
else x->p = div(y->m - x->m, x->k - y->k);
return x->p >= y->p;
}
void add(ll k, ll m) {
k = -k,m = -m;
auto z = insert({k, m, 0}), y = z++, x = y;
while (isect(y, z)) z = erase(z);
if (x != begin() && isect(--x, y)) isect(x, y = erase(y));
while ((y = x) != begin() && (--x)->p >= y->p)
isect(x, erase(y));
}
ll query(ll x) {
assert(!empty());
auto l = *lower_bound(x);
return -(l.k * x + l.m);
}
};
const ll MAXN = 1e5;
vector <pll> g[MAXN+100];
ll a[MAXN+100],b[MAXN+100];
ll full_sz;
ll sz[MAXN+100];
ll pa[MAXN+100];
LineContainer s[MAXN+100];
vector <pll> anc[MAXN+100];
ll dist[MAXN+100];
bool del[MAXN+100];
ll order[MAXN+100];
void dfs_sz(ll u,ll p){
sz[u] = 1;
for (auto tmp:g[u]){
ll v = tmp.fi;
if (v == p || del[v])continue;
dfs_sz(v,u);
sz[u] += sz[v];
}
}
ll f(ll u,ll p){
for (auto tmp:g[u]){
ll v = tmp.fi;
if (del[v] || v == p)continue;
if (sz[v] * 2 > full_sz){
return f(v,u);
}
}
return u;
}
ll find_centroid(ll u){
dfs_sz(u,u);
full_sz = sz[u];
return f(u,u);
}
void dfs_dist(ll u,ll p,ll root){
// cout<<u<<' '<<p<<' '<<root<<endl;
if (u == p)dist[u] = 0;
anc[u].push_back(MP(root,dist[u]));
for (auto tmp:g[u]){
ll v = tmp.fi;
if (v == p || del[v])continue;
dist[v] = dist[u] + tmp.se;
dfs_dist(v,u,root);
}
}
void solve(ll u,ll p){
pa[u] = p;
u = find_centroid(u);
dfs_dist(u,u,u);
{
del[u] = 1;
for (auto v:g[u]){
if (!del[v.fi])solve(v.fi,u);
}
}
}
std::vector<long long> travel(std::vector<long long> A,
std::vector<int> B, std::vector<int> U, std::vector<int> V, std::vector<int> W)
{
ll n = sz(A);
for (ll i = 0;i < n - 1;i ++){
g[U[i]+1].push_back(MP(V[i]+1,W[i]));
g[V[i]+1].push_back(MP(U[i]+1,W[i]));
}
for (ll i = 0;i < n;i ++)a[i+1] = A[i],b[i+1] = B[i];
solve(1,1);
iota(order+1,order+1+n,1);
sort(order+1,order+1+n,[&](ll x,ll y){return b[x] > b[y];});
vector <ll> ans(n-1);
for (ll i = 1;i <= n;i ++){
ll id = order[i];
ll res = INF;
if (id==1)res = 0;
else {
for (auto x:anc[id]){
res = min(res,s[x.fi].query(x.se));
}
}
if (id >= 2)ans[id-2]=res;
for (auto x:anc[id]){
// cout<<id<<' '<<x.se<<' '<<b[id]<<' '<<res+a[id]+b[id]*x.se<<'\n';
s[x.fi].add(b[id],res+a[id]+b[id]*x.se);
}
}
for (ll i = 1;i <= n;i ++){
ll id = order[i];
ll res = INF;
if (id==1)res = 0;
else {
for (auto x:anc[id]){
res = min(res,s[x.fi].query(x.se));
}
}
if (id >= 2)ans[id-2]=res;
}
return ans;
}
詳細信息
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 0
Runtime Error
input:
2 684124582850 713748627948 74361 256955 0 1 661088
output:
Unauthorized output
result:
Subtask #2:
score: 0
Runtime Error
Test #31:
score: 0
Runtime Error
input:
100000 746699125678 374834842799 250803643493 620187038832 454433387570 406226564003 897157438699 99473514061 734784419618 503968957100 363935477037 277126009840 52078020050 990757079812 847235285349 950784717285 271017141367 861087225700 996035427219 520682200664 282013988419 415183977876 882007771...
output:
Unauthorized output
result:
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Runtime Error
Test #69:
score: 0
Runtime Error
input:
100000 15175010 23519365 21177669 27079342 9089 16784452 29693960 23124925 17048604 10179491 12828214 24992902 8483134 2928073 23807522 7332137 17421520 28460746 1607282 13224363 11900728 11794692 11495061 4687109 23460275 7657982 27417256 16978162 7326803 23083826 24942987 16610314 12147303 2828271...
output:
Unauthorized output
result:
Subtask #5:
score: 0
Runtime Error
Test #94:
score: 0
Runtime Error
input:
99281 551670361798 568902251563 418071776626 697635341894 641578820039 117221079324 812766431051 425410617978 663769685693 282144284527 799662290178 749088952784 586626406385 122473825417 459510657357 871705247919 443707710712 735612808044 237919555727 829939639783 122127143240 616906466299 24431898...
output:
Unauthorized output
result:
Subtask #6:
score: 0
Skipped
Dependency #1:
0%