結果

問題 No.1308 ジャンプビーコン
ユーザー tailstails
提出日時 2020-12-05 23:52:06
言語 cLay
(20240104-1)
結果
AC  
実行時間 80 ms / 4,000 ms
コード長 1,268 bytes
コンパイル時間 3,004 ms
コンパイル使用メモリ 175,728 KB
実行使用メモリ 78,000 KB
最終ジャッジ日時 2023-09-19 01:54:14
合計ジャッジ時間 6,008 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,460 KB
testcase_01 AC 2 ms
7,436 KB
testcase_02 AC 3 ms
7,484 KB
testcase_03 AC 2 ms
7,440 KB
testcase_04 AC 2 ms
7,460 KB
testcase_05 AC 2 ms
7,452 KB
testcase_06 AC 2 ms
7,476 KB
testcase_07 AC 2 ms
7,448 KB
testcase_08 AC 2 ms
7,440 KB
testcase_09 AC 2 ms
7,460 KB
testcase_10 AC 2 ms
7,616 KB
testcase_11 AC 2 ms
7,444 KB
testcase_12 AC 2 ms
7,440 KB
testcase_13 AC 3 ms
7,576 KB
testcase_14 AC 2 ms
7,584 KB
testcase_15 AC 3 ms
7,592 KB
testcase_16 AC 3 ms
7,544 KB
testcase_17 AC 3 ms
7,560 KB
testcase_18 AC 3 ms
7,668 KB
testcase_19 AC 4 ms
7,824 KB
testcase_20 AC 3 ms
7,652 KB
testcase_21 AC 3 ms
7,680 KB
testcase_22 AC 3 ms
7,916 KB
testcase_23 AC 3 ms
7,464 KB
testcase_24 AC 2 ms
7,484 KB
testcase_25 AC 3 ms
7,464 KB
testcase_26 AC 3 ms
7,580 KB
testcase_27 AC 3 ms
7,536 KB
testcase_28 AC 3 ms
7,728 KB
testcase_29 AC 29 ms
29,716 KB
testcase_30 AC 28 ms
29,500 KB
testcase_31 AC 80 ms
78,000 KB
testcase_32 AC 23 ms
29,600 KB
testcase_33 AC 28 ms
29,816 KB
testcase_34 AC 3 ms
7,532 KB
testcase_35 AC 3 ms
7,544 KB
testcase_36 AC 3 ms
7,612 KB
testcase_37 AC 3 ms
7,692 KB
testcase_38 AC 5 ms
8,088 KB
testcase_39 AC 5 ms
8,156 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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);
}
0