結果

問題 No.1545 [Cherry 2nd Tune N] Anthem
ユーザー 沙耶花沙耶花
提出日時 2021-06-11 21:37:24
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 144 ms / 3,000 ms
コード長 1,539 bytes
コンパイル時間 4,259 ms
コンパイル使用メモリ 266,060 KB
実行使用メモリ 24,168 KB
最終ジャッジ日時 2023-08-21 11:48:00
合計ジャッジ時間 16,633 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 39 ms
11,432 KB
testcase_05 AC 118 ms
17,744 KB
testcase_06 AC 48 ms
9,676 KB
testcase_07 AC 55 ms
11,832 KB
testcase_08 AC 114 ms
11,184 KB
testcase_09 AC 46 ms
6,444 KB
testcase_10 AC 45 ms
10,068 KB
testcase_11 AC 61 ms
11,828 KB
testcase_12 AC 94 ms
16,200 KB
testcase_13 AC 35 ms
8,032 KB
testcase_14 AC 37 ms
11,096 KB
testcase_15 AC 14 ms
5,060 KB
testcase_16 AC 53 ms
13,904 KB
testcase_17 AC 31 ms
5,092 KB
testcase_18 AC 123 ms
14,400 KB
testcase_19 AC 58 ms
10,112 KB
testcase_20 AC 30 ms
5,440 KB
testcase_21 AC 65 ms
17,840 KB
testcase_22 AC 67 ms
15,260 KB
testcase_23 AC 82 ms
8,680 KB
testcase_24 AC 5 ms
4,380 KB
testcase_25 AC 4 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 4 ms
4,376 KB
testcase_28 AC 6 ms
4,376 KB
testcase_29 AC 6 ms
4,380 KB
testcase_30 AC 4 ms
4,380 KB
testcase_31 AC 5 ms
4,376 KB
testcase_32 AC 3 ms
4,376 KB
testcase_33 AC 6 ms
4,380 KB
testcase_34 AC 5 ms
4,376 KB
testcase_35 AC 11 ms
4,380 KB
testcase_36 AC 9 ms
4,380 KB
testcase_37 AC 3 ms
4,376 KB
testcase_38 AC 6 ms
4,376 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 3 ms
4,376 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 5 ms
4,380 KB
testcase_43 AC 5 ms
4,380 KB
testcase_44 AC 3 ms
4,376 KB
testcase_45 AC 2 ms
4,376 KB
testcase_46 AC 4 ms
4,380 KB
testcase_47 AC 6 ms
4,560 KB
testcase_48 AC 9 ms
6,636 KB
testcase_49 AC 10 ms
4,980 KB
testcase_50 AC 27 ms
6,244 KB
testcase_51 AC 3 ms
4,376 KB
testcase_52 AC 26 ms
6,244 KB
testcase_53 AC 8 ms
4,780 KB
testcase_54 AC 2 ms
4,376 KB
testcase_55 AC 16 ms
5,904 KB
testcase_56 AC 3 ms
4,380 KB
testcase_57 AC 20 ms
5,368 KB
testcase_58 AC 9 ms
4,848 KB
testcase_59 AC 3 ms
4,376 KB
testcase_60 AC 3 ms
4,380 KB
testcase_61 AC 5 ms
4,380 KB
testcase_62 AC 11 ms
4,720 KB
testcase_63 AC 9 ms
4,376 KB
testcase_64 AC 144 ms
20,608 KB
testcase_65 AC 4 ms
4,376 KB
testcase_66 AC 60 ms
24,168 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
	
	int N,S,T,K;
	cin>>N>>S>>T>>K;
	
	S--;T--;
	
	vector<long long> X(N);
	rep(i,N)scanf("%lld",&X[i]);
	
	int M;
	cin>>M;
	
	vector<int> to(M);
	vector<long long> cost(M);
	vector<vector<int>> E(N);
	
	rep(i,M){
		int A;
		scanf("%d %d %lld",&A,&to[i],&cost[i]);
		to[i]--;
		A--;
		E[A].push_back(i);
	}
	
	vector<long long> dis(N*(K+1),Inf);
	priority_queue<pair<long long,int>,vector<pair<long long,int>>,greater<pair<long long,int>>> Q;
	Q.emplace(X[S],S+N);
	dis[S+N] = X[S];
	
	vector<int> pre(N*(K+1),-1);
	
	while(Q.size()>0){
		long long D = Q.top().first;
		int u = Q.top().second%N;
		int cnt = Q.top().second/N;
		Q.pop();
		
		if(dis[u+cnt*N]!=D)continue;
		
		rep(i,E[u].size()){
			int v = to[E[u][i]];
			long long D2 = D + cost[E[u][i]] + X[v];
			int nxt = min(K,cnt+1)*N + v;
			if(dis[nxt]>D2){
				dis[nxt] = D2;
				Q.emplace(D2,nxt);
				pre[nxt] = cnt*N + u;
			}
		}
	}

	int cur = T+K*N;
	
	if(dis[cur]==Inf){
		cout<<"Impossible"<<endl;
		return 0;
	}
	cout<<"Possible"<<endl;
	cout<<dis[cur]<<endl;
	vector<int> ans(1,cur);
	
	
	while(pre[cur] != -1){
		cur = pre[cur];
		ans.push_back(cur);
	}
	
	reverse(ans.begin(),ans.end());
	cout<<ans.size()<<endl;
	
	rep(i,ans.size()){
		ans[i] = ans[i]%N;
		ans[i]++;
		if(i!=0)cout<<' ';
		cout<<ans[i];
	}
	cout<<endl;
	
	return 0;
}
0