結果

問題 No.1308 ジャンプビーコン
ユーザー 沙耶花沙耶花
提出日時 2020-12-05 14:31:02
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 881 ms / 4,000 ms
コード長 1,602 bytes
コンパイル時間 2,682 ms
コンパイル使用メモリ 213,820 KB
実行使用メモリ 74,632 KB
最終ジャッジ日時 2023-10-13 21:52:32
合計ジャッジ時間 19,886 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 2 ms
4,352 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,352 KB
testcase_13 AC 11 ms
4,348 KB
testcase_14 AC 11 ms
4,348 KB
testcase_15 AC 10 ms
4,352 KB
testcase_16 AC 11 ms
4,352 KB
testcase_17 AC 11 ms
4,348 KB
testcase_18 AC 878 ms
74,128 KB
testcase_19 AC 870 ms
74,252 KB
testcase_20 AC 881 ms
74,352 KB
testcase_21 AC 869 ms
74,132 KB
testcase_22 AC 874 ms
74,168 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 2 ms
4,352 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 726 ms
74,076 KB
testcase_27 AC 701 ms
74,148 KB
testcase_28 AC 668 ms
74,228 KB
testcase_29 AC 750 ms
74,632 KB
testcase_30 AC 755 ms
74,628 KB
testcase_31 AC 505 ms
74,440 KB
testcase_32 AC 794 ms
74,596 KB
testcase_33 AC 857 ms
74,564 KB
testcase_34 AC 696 ms
74,144 KB
testcase_35 AC 713 ms
74,152 KB
testcase_36 AC 741 ms
74,200 KB
testcase_37 AC 730 ms
74,136 KB
testcase_38 AC 881 ms
74,292 KB
testcase_39 AC 853 ms
74,296 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:13:33: 警告: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘-fconcepts’
   13 | vector<long long> get(int start,auto &E){
      |                                 ^~~~
main.cpp:34:10: 警告: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘-fconcepts’
   34 | void dfs(auto &E,auto &dp,auto &ndp,auto &dis,int now,int F,int P,int p=-1){
      |          ^~~~
main.cpp:34:18: 警告: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘-fconcepts’
   34 | void dfs(auto &E,auto &dp,auto &ndp,auto &dis,int now,int F,int P,int p=-1){
      |                  ^~~~
main.cpp:34:27: 警告: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘-fconcepts’
   34 | void dfs(auto &E,auto &dp,auto &ndp,auto &dis,int now,int F,int P,int p=-1){
      |                           ^~~~
main.cpp:34:37: 警告: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘-fconcepts’
   34 | void dfs(auto &E,auto &dp,auto &ndp,auto &dis,int now,int F,int P,int p=-1){
      |                                     ^~~~

ソースコード

diff #

#pragma target("avx2")
#pragma optimize("O3")
#pragma optimize("unroll-loops")

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



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 C;
void dfs(auto &E,auto &dp,auto &ndp,auto &dis,int now,int F,int P,int p=-1){
	
	if(F!=now)ndp[now] = min(ndp[now],dp[now] + C + dis[now][P]);
	else ndp[now] = min(ndp[now],dp[now] + dis[now][P]);
	
	rep(i,E[now].size()){
		int to = E[now][i].first;
		if(to==p)continue;
		dfs(E,dp,ndp,dis,to,F,P,now);
		ndp[now] = min(ndp[now],ndp[to]);
	}
}

int main(){
	
	int N,Q;
	
	cin>>N>>Q>>C;
	
	vector E(N,vector<pair<int,long long>>());
	rep(i,N-1){
		int u,v,l;
		scanf("%d %d %d",&u,&v,&l);
		
		u--;v--;
		E[u].emplace_back(v,l);
		E[v].emplace_back(u,l);
	}
	
	vector<int> x(Q);
	rep(i,Q){
		scanf("%d",&x[i]);
		x[i]--;
	}
	
	vector dis(N,vector<long long>());
	
	rep(i,N){
		dis[i] = get(i,E);
	}
	
	vector<long long> dp(N,Inf);
	
	dp[x[0]] = 0LL;
	
	rep(i,Q-1){
		vector<long long> ndp(N,Inf);

		dfs(E,dp,ndp,dis,x[i+1],x[i],x[i+1]);
		
		rep(j,N){
			ndp[j] = min(ndp[j],dp[j] + dis[x[i]][x[i+1]]);
		}
		
		swap(dp,ndp);
		
		
	}
	
	long long ans = Inf;
	rep(i,N)ans = min(ans,dp[i]);
	
	cout<<ans<<endl;
	
	
    return 0;
}
0