結果

問題 No.1545 [Cherry 2nd Tune N] Anthem
ユーザー 👑 kmjpkmjp
提出日時 2021-06-12 00:50:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 923 ms / 3,000 ms
コード長 1,843 bytes
コンパイル時間 2,292 ms
コンパイル使用メモリ 213,420 KB
実行使用メモリ 165,792 KB
最終ジャッジ日時 2024-05-08 21:37:31
合計ジャッジ時間 20,941 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
38,656 KB
testcase_01 AC 27 ms
38,656 KB
testcase_02 AC 27 ms
38,784 KB
testcase_03 AC 25 ms
38,912 KB
testcase_04 AC 197 ms
71,808 KB
testcase_05 AC 773 ms
165,396 KB
testcase_06 AC 244 ms
77,184 KB
testcase_07 AC 172 ms
63,360 KB
testcase_08 AC 923 ms
149,152 KB
testcase_09 AC 230 ms
70,400 KB
testcase_10 AC 76 ms
44,544 KB
testcase_11 AC 349 ms
96,896 KB
testcase_12 AC 630 ms
137,980 KB
testcase_13 AC 126 ms
58,496 KB
testcase_14 AC 217 ms
75,264 KB
testcase_15 AC 44 ms
41,856 KB
testcase_16 AC 310 ms
91,392 KB
testcase_17 AC 65 ms
44,288 KB
testcase_18 AC 168 ms
52,436 KB
testcase_19 AC 258 ms
80,916 KB
testcase_20 AC 199 ms
72,320 KB
testcase_21 AC 346 ms
96,000 KB
testcase_22 AC 161 ms
62,592 KB
testcase_23 AC 168 ms
63,360 KB
testcase_24 AC 48 ms
47,488 KB
testcase_25 AC 59 ms
52,608 KB
testcase_26 AC 29 ms
38,784 KB
testcase_27 AC 41 ms
43,392 KB
testcase_28 AC 84 ms
58,240 KB
testcase_29 AC 67 ms
54,272 KB
testcase_30 AC 57 ms
50,432 KB
testcase_31 AC 63 ms
51,328 KB
testcase_32 AC 39 ms
44,160 KB
testcase_33 AC 80 ms
57,344 KB
testcase_34 AC 65 ms
52,736 KB
testcase_35 AC 264 ms
98,816 KB
testcase_36 AC 195 ms
82,944 KB
testcase_37 AC 33 ms
41,088 KB
testcase_38 AC 92 ms
59,392 KB
testcase_39 AC 35 ms
41,856 KB
testcase_40 AC 43 ms
46,336 KB
testcase_41 AC 32 ms
39,936 KB
testcase_42 AC 57 ms
49,664 KB
testcase_43 AC 80 ms
53,248 KB
testcase_44 AC 33 ms
39,808 KB
testcase_45 AC 32 ms
40,064 KB
testcase_46 AC 53 ms
50,432 KB
testcase_47 AC 73 ms
58,368 KB
testcase_48 AC 76 ms
61,696 KB
testcase_49 AC 152 ms
78,592 KB
testcase_50 AC 240 ms
101,376 KB
testcase_51 AC 36 ms
41,984 KB
testcase_52 AC 446 ms
145,152 KB
testcase_53 AC 106 ms
70,272 KB
testcase_54 AC 43 ms
44,288 KB
testcase_55 AC 288 ms
110,592 KB
testcase_56 AC 32 ms
39,808 KB
testcase_57 AC 233 ms
93,824 KB
testcase_58 AC 141 ms
83,712 KB
testcase_59 AC 39 ms
44,160 KB
testcase_60 AC 39 ms
43,648 KB
testcase_61 AC 77 ms
55,168 KB
testcase_62 AC 212 ms
88,832 KB
testcase_63 AC 101 ms
60,672 KB
testcase_64 AC 616 ms
165,792 KB
testcase_65 AC 41 ms
43,216 KB
testcase_66 AC 271 ms
110,336 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,S,T,K,M;
int X[101010];
int A[101010],B[101010];
vector<vector<int>> E[1505050];
ll dp[2020202];
int from[2020202];
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>S>>T>>K;
	S--,T--;
	FOR(i,N) cin>>X[i];
	cin>>M;
	FOR(i,M) {
		cin>>x>>y>>k;
		x--,y--;
		FOR(j,K-1) {
			E[N*j+x].push_back({N*(j+1)+y,i,X[y]+k});
		}
		E[N*(K-1)+x].push_back({N*(K-1)+y,i,X[y]+k});
	}
	FOR(i,N*K) dp[i]=1LL<<60;
	priority_queue<pair<ll,int>> Q;
	dp[S]=X[S];
	Q.push({-X[S],S});
	while(Q.size()) {
		ll co=-Q.top().first;
		int cur=Q.top().second;
		Q.pop();
		if(dp[cur]!=co) continue;
		FORR(e,E[cur]) if(dp[e[0]]>co+e[2]) {
			dp[e[0]]=co+e[2];
			from[e[0]]=cur;
			Q.push({-dp[e[0]],e[0]});
		}
	}
	
	if(dp[N*(K-1)+T]==1LL<<60) {
		cout<<"Impossible"<<endl;
	}
	else {
		cout<<"Possible"<<endl;
		cout<<dp[N*(K-1)+T]<<endl;
		int cur=N*(K-1)+T;
		vector<int> V;
		while(cur!=S) {
			V.push_back(cur);
			cur=from[cur];
		}
		V.push_back(S);
		reverse(ALL(V));
		cout<<V.size()<<endl;
		FORR(v,V) cout<<(v%N+1)<<" ";
		cout<<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