結果
| 問題 |
No.1308 ジャンプビーコン
|
| コンテスト | |
| ユーザー |
tails
|
| 提出日時 | 2020-12-05 23:52:06 |
| 言語 | cLay (20241019-1) |
| 結果 |
AC
|
| 実行時間 | 81 ms / 4,000 ms |
| コード長 | 1,268 bytes |
| コンパイル時間 | 3,737 ms |
| コンパイル使用メモリ | 178,636 KB |
| 実行使用メモリ | 51,200 KB |
| 最終ジャッジ日時 | 2024-07-05 14:48:38 |
| 合計ジャッジ時間 | 5,077 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 37 |
ソースコード
int u[3d3],v[3d3],l[3d3],x[3d3];
struct Node {
int parent;
int depth;
ll cost;
};
Node nodes[3d3];
int visited[3d3];
ll saveds[3d3];
int steps[10000000],fs[10000000];
int stepn;
ll totalcost;
ll totalsaved;
wgraph<int> g;
HLD h;
void f1(int i,int p){
rep(k,g.es[i]){
int j=g.edge[i][k];
if(j!=p){
nodes[j].parent=i;
nodes[j].depth=nodes[i].depth+1;
nodes[j].cost=g.cost[i][k];
f1(j,i);
}
}
}
{
int @n,@q,@c;
rd((u--,v--,l)(n-1));
rd((x--)(q));
g.setEdge(n,n-1,u,v,l);
h.init(g.g);
f1(0,-1);
{
int p=x[0];
steps[stepn++]=p;
rep(k,q){
int y=x[k];
int a=h.lca(p,y);
while(p!=a){
p=nodes[p].parent;
steps[stepn++]=p;
}
stepn+=nodes[y].depth-nodes[a].depth;
int n=stepn;
while(y!=a){
steps[--n]=y;
y=nodes[y].parent;
}
p=x[k];
fs[stepn-1]=1;
}
}
{
int p=steps[0];
visited[p]=1;
ll saved=0;
rep(stepi,1,stepn){
int y=steps[stepi];
int localcost=(nodes[y].parent==p?nodes[y].cost:nodes[p].cost);
saved+=localcost;
totalcost+=localcost;
if(visited[y]){
if(totalsaved<saveds[y]+saved-c){
totalsaved=saveds[y]+saved-c;
}
}
visited[y]=1;
if(fs[stepi]){
saved=0;
}
saveds[y]=totalsaved;
p=y;
}
}
wt(totalcost-totalsaved);
}
tails