結果

問題 No.1308 ジャンプビーコン
ユーザー 👑 kmjpkmjp
提出日時 2020-12-05 00:11:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,722 ms / 4,000 ms
コード長 1,902 bytes
コンパイル時間 2,303 ms
コンパイル使用メモリ 210,872 KB
実行使用メモリ 75,624 KB
最終ジャッジ日時 2023-10-13 12:21:59
合計ジャッジ時間 51,786 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 2 ms
4,352 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 4 ms
4,348 KB
testcase_09 AC 4 ms
4,348 KB
testcase_10 AC 4 ms
4,348 KB
testcase_11 AC 4 ms
4,352 KB
testcase_12 AC 4 ms
4,352 KB
testcase_13 AC 122 ms
8,108 KB
testcase_14 AC 123 ms
8,068 KB
testcase_15 AC 122 ms
8,288 KB
testcase_16 AC 122 ms
8,176 KB
testcase_17 AC 124 ms
8,300 KB
testcase_18 AC 2,599 ms
75,364 KB
testcase_19 AC 2,615 ms
75,440 KB
testcase_20 AC 2,541 ms
75,508 KB
testcase_21 AC 2,499 ms
75,348 KB
testcase_22 AC 2,607 ms
75,596 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 7 ms
4,352 KB
testcase_25 AC 7 ms
4,348 KB
testcase_26 AC 2,669 ms
75,360 KB
testcase_27 AC 2,699 ms
75,448 KB
testcase_28 AC 2,604 ms
75,404 KB
testcase_29 AC 2,014 ms
75,432 KB
testcase_30 AC 2,023 ms
75,512 KB
testcase_31 AC 1,797 ms
75,460 KB
testcase_32 AC 2,000 ms
75,432 KB
testcase_33 AC 2,184 ms
75,432 KB
testcase_34 AC 2,680 ms
75,376 KB
testcase_35 AC 2,682 ms
75,504 KB
testcase_36 AC 2,463 ms
75,624 KB
testcase_37 AC 2,428 ms
75,384 KB
testcase_38 AC 2,722 ms
75,336 KB
testcase_39 AC 2,702 ms
75,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N,Q,C;
int X[3030];
vector<pair<int,int>> E[3030];
ll D[3030][3030];

ll from[3030];
ll to[3030];
ll d[3030];

void dfs(int cur,int pre,int start,ll d) {
	D[start][cur]=d;
	FORR(e,E[cur]) if(e.first!=pre) dfs(e.first,cur,start,d+e.second);
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>Q>>C;
	FOR(i,N-1) {
		cin>>x>>y>>r;
		E[x-1].push_back({y-1,r});
		E[y-1].push_back({x-1,r});
	}
	FOR(i,N) dfs(i,i,i,0);
	FOR(i,Q) {
		cin>>X[i];
		X[i]--;
	}
	FOR(i,N) from[i]=1LL<<60;
	from[X[0]]=0;
	FOR(i,Q-1) {
		int s=X[i],t=X[i+1];
		// 動かさない
		FOR(j,N) to[j]=from[j]+D[s][t];
		
		priority_queue<pair<ll,int>> PQ;
		FOR(j,N) {
			
			if(j==s) d[j]=from[j];
			else d[j]=from[j]+C;
			PQ.push({-d[j],j});
		}
		while(PQ.size()) {
			ll co=-PQ.top().first;
			int cur=PQ.top().second;
			PQ.pop();
			if(d[cur]!=co) continue;
			FORR(e,E[cur]) if(d[e.first]>co+e.second) {
				d[e.first]=co+e.second;
				PQ.push({-d[e.first],e.first});
			}
		}
		FOR(j,N) to[j]=min(to[j],d[j]+D[j][t]);
		swap(from,to);
	}
	ll ret=1LL<<60;
	FOR(i,N) ret=min(ret,from[i]);
	cout<<ret<<endl;
	
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0