結果

問題 No.1308 ジャンプビーコン
ユーザー tailstails
提出日時 2020-12-06 01:05:49
言語 cLay
(20240104-1)
結果
AC  
実行時間 156 ms / 4,000 ms
コード長 1,029 bytes
コンパイル時間 3,225 ms
コンパイル使用メモリ 176,272 KB
実行使用メモリ 116,628 KB
最終ジャッジ日時 2023-09-19 01:54:20
合計ジャッジ時間 5,853 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
11,484 KB
testcase_01 AC 3 ms
11,548 KB
testcase_02 AC 3 ms
11,568 KB
testcase_03 AC 3 ms
11,668 KB
testcase_04 AC 3 ms
11,512 KB
testcase_05 AC 3 ms
11,544 KB
testcase_06 AC 3 ms
11,568 KB
testcase_07 AC 3 ms
11,536 KB
testcase_08 AC 3 ms
11,604 KB
testcase_09 AC 3 ms
11,520 KB
testcase_10 AC 3 ms
11,512 KB
testcase_11 AC 3 ms
11,788 KB
testcase_12 AC 3 ms
11,488 KB
testcase_13 AC 4 ms
13,644 KB
testcase_14 AC 4 ms
13,656 KB
testcase_15 AC 4 ms
13,644 KB
testcase_16 AC 4 ms
13,868 KB
testcase_17 AC 5 ms
13,616 KB
testcase_18 AC 13 ms
46,484 KB
testcase_19 AC 12 ms
46,568 KB
testcase_20 AC 12 ms
46,480 KB
testcase_21 AC 11 ms
46,460 KB
testcase_22 AC 11 ms
46,512 KB
testcase_23 AC 3 ms
11,656 KB
testcase_24 AC 3 ms
11,580 KB
testcase_25 AC 4 ms
11,584 KB
testcase_26 AC 11 ms
46,436 KB
testcase_27 AC 10 ms
46,516 KB
testcase_28 AC 11 ms
46,452 KB
testcase_29 AC 59 ms
68,324 KB
testcase_30 AC 58 ms
68,480 KB
testcase_31 AC 156 ms
116,628 KB
testcase_32 AC 47 ms
68,232 KB
testcase_33 AC 57 ms
68,232 KB
testcase_34 AC 11 ms
46,336 KB
testcase_35 AC 11 ms
46,332 KB
testcase_36 AC 11 ms
46,392 KB
testcase_37 AC 11 ms
46,432 KB
testcase_38 AC 13 ms
46,916 KB
testcase_39 AC 13 ms
46,996 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

int u[3d3],v[3d3],l[3d3],x[3d3];


int costs[1d7];
int visited[3d3];
ll saveds[3d3];
int steps[1d7],fs[1d7];
int stepn;

ll totalcost;
ll totalsaved;

wgraph<int> g;
HLD h;

{
	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);
	rep(i,n-1){
		costs[u[i]+3000*v[i]]=l[i];
		costs[v[i]+3000*u[i]]=l[i];
	}
	{
		int p=x[0];
		steps[stepn++]=p;
		rep(k,q){
			int y=x[k];
			int a=h.lca(p,y);
			while(p!=a){
				p=h.up(p);
				steps[stepn++]=p;
			}
			stepn+=h.depth(y)-h.depth(a);
			int n=stepn;
			while(y!=a){
				steps[--n]=y;
				y=h.up(y);
			}
			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=costs[p+3000*y];
			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