結果

問題 No.1308 ジャンプビーコン
ユーザー 沙耶花沙耶花
提出日時 2020-12-05 13:33:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 3,924 bytes
コンパイル時間 4,476 ms
コンパイル使用メモリ 240,908 KB
実行使用メモリ 245,276 KB
最終ジャッジ日時 2023-10-13 21:29:30
合計ジャッジ時間 11,633 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
78,760 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 6 ms
4,348 KB
testcase_09 AC 6 ms
4,348 KB
testcase_10 AC 6 ms
4,352 KB
testcase_11 AC 6 ms
4,356 KB
testcase_12 AC 6 ms
4,352 KB
testcase_13 AC 491 ms
4,368 KB
testcase_14 AC 464 ms
4,352 KB
testcase_15 AC 479 ms
4,348 KB
testcase_16 AC 475 ms
4,348 KB
testcase_17 AC 473 ms
4,352 KB
testcase_18 TLE -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:9:33: 警告: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘-fconcepts’
    9 | vector<long long> get(int start,auto &E){
      |                                 ^~~~

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/lazysegtree>
using namespace atcoder;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000000000000

vector<long long> get(int start,auto &E){
	vector<long long> dis(E.size(),Inf);
	dis[start] = 0;
	queue<int> Q;
	Q.push(start);
	
	while(Q.size()>0){
		int u = Q.front();
		Q.pop();
		rep(i,E[u].size()){
			int v = E[u][i].first;
			if(dis[v]!=Inf)continue;
			dis[v] = dis[u] + E[u][i].second;
			Q.push(v);
		}
	}
	
	return dis;
}

long long op(long long a,long long b){
	return min(a,b);
}

long long e(){
	return Inf;
}

long long mapping(long long a,long long b){
	if(a==-1)return b;
	return a;
}

long long composition(long long a,long long b){
	if(a==-1)return b;
	if(b==-1)return a;
	return a;
}

long long id(){
	return -1;
}

struct HLD{
	vector<int> sz,parent,depth,root,pos;
	vector<int> arr;
	HLD(vector<vector<int>> &E){
		sz.resize(E.size(),1);
		parent.resize(E.size(),0);
		depth.resize(E.size(),0);
		root.resize(E.size(),0);
		pos.resize(E.size(),0);
		
		dfs(0,-1,E);
		dfs2(0,-1,E,0);
	}
	
	void dfs(int now,int p,vector<vector<int>> &E){
		parent[now] = p;
		if(p==-1){
			depth[now] = 0;
		}
		else{
			depth[now] = depth[p]+1;
		}
		for(int i=0;i<E[now].size();i++){
			int to = E[now][i];
			if(to==p)continue;
			dfs(to,now,E);
			sz[now] += sz[to];
		}
	}
	
	void dfs2(int now,int p,vector<vector<int>> &E,int r){
		pos[now] = arr.size();
		arr.push_back(now);
		root[now] = r;
		int maxi = 0;
		int ind = -1;
		for(int i=0;i<E[now].size();i++){
			int to = E[now][i];
			if(to==p)continue;
			if(maxi<sz[to]){
				maxi = sz[to];
				ind = to;
			}
		}
		if(ind==-1)return;
		dfs2(ind,now,E,r);
		for(int i=0;i<E[now].size();i++){
			int to = E[now][i];
			if(to==p||to==ind)continue;
			dfs2(to,now,E,to);
		}
	}
	
	vector<pair<int,int>> query(int u,int v){
		vector<pair<int,int>> ret;
		int t = 0;
		while(root[u]!=root[v]){
			if(depth[root[u]] <= depth[root[v]]){
				ret.insert(ret.begin()+t,{pos[root[v]], pos[v]});
				v = parent[root[v]];
			}
			else{
				ret.insert(ret.begin()+t,{pos[u],pos[root[u]]});
				u = parent[root[u]];
				t++;
			}
		}
		ret.insert(ret.begin()+t,{pos[u],pos[v]});
		return ret;
	}
	
	int lca(int u,int v){
		for(;;v=parent[root[v]]){
			if(pos[u]>pos[v])swap(u,v);
			if(root[u]==root[v])return u;
		}
	}
	
	int get_distance(int u,int v){
		return depth[u] + depth[v] - 2 * depth[lca(u,v)];
	}
	
};

int main(){
	
	int N,Q;
	long long C;
	cin>>N>>Q>>C;
	
	vector E(N,vector<pair<int,long long>>());
	vector EE(N,vector<int>());
	rep(i,N-1){
		int u,v,l;
		cin>>u>>v>>l;
		
		u--;v--;
		E[u].emplace_back(v,l);
		E[v].emplace_back(u,l);
		
		EE[u].push_back(v);
		EE[v].push_back(u);
	}
	
	vector<int> x(Q);
	rep(i,Q){
		cin>>x[i];
		x[i]--;
	}
	
	vector dis(N,vector<long long>());
	
	rep(i,N){
		dis[i] = get(i,E);
	}
	
	HLD H(EE);
	
	lazy_segtree<long long,op,e,long long,mapping,composition,id> seg(N);
	seg.set(H.pos[x[0]],0LL);
	
	rep(i,Q-1){
		lazy_segtree<long long,op,e,long long,mapping,composition,id> nseg(N);

		vector<pair<long long,int>> V;
		
		rep(j,N){
			if(j==x[i]){
				long long t = seg.get(H.pos[j])+dis[j][x[i+1]];
				V.emplace_back(t,j);
			}
			else{
				long long t = seg.get(H.pos[j])+dis[j][x[i+1]]+C;
				V.emplace_back(t,j);
			}
			
			V.emplace_back(seg.get(H.pos[j]) + min(dis[x[i]][x[i+1]],C+dis[j][x[i+1]]),-j-1);
			
		}
		
		sort(V.rbegin(),V.rend());
		
		rep(j,V.size()){		
			long long t = V[j].first;
			if(t>=Inf)continue;
			
			int ind = V[j].second;
			if(ind<0){
				ind++;
				ind *= -1;
				
				nseg.set(H.pos[ind],t);
				continue;
			}
			auto ret = H.query(ind,x[i+1]);
			for(auto &x:ret){
				if(x.first>x.second)swap(x.first,x.second);
				nseg.apply(x.first,x.second+1,t);
			}
			
			
		}
		
		swap(seg,nseg);
		
	//	cout<<seg.all_prod()<<endl;
		
	}
	
	cout<<seg.all_prod()<<endl;
	
	
    return 0;
}
0