結果

問題 No.1545 [Cherry 2nd Tune N] Anthem
ユーザー abc3abc3
提出日時 2021-06-12 04:51:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 142 ms / 3,000 ms
コード長 1,483 bytes
コンパイル時間 1,040 ms
コンパイル使用メモリ 98,676 KB
実行使用メモリ 26,380 KB
最終ジャッジ日時 2023-08-21 23:10:30
合計ジャッジ時間 14,710 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,456 KB
testcase_01 AC 3 ms
6,508 KB
testcase_02 AC 4 ms
6,456 KB
testcase_03 AC 4 ms
6,452 KB
testcase_04 AC 40 ms
13,392 KB
testcase_05 AC 114 ms
19,812 KB
testcase_06 AC 46 ms
11,784 KB
testcase_07 AC 54 ms
12,776 KB
testcase_08 AC 99 ms
13,052 KB
testcase_09 AC 40 ms
8,500 KB
testcase_10 AC 42 ms
9,600 KB
testcase_11 AC 60 ms
13,848 KB
testcase_12 AC 93 ms
18,208 KB
testcase_13 AC 34 ms
10,216 KB
testcase_14 AC 36 ms
13,576 KB
testcase_15 AC 15 ms
7,668 KB
testcase_16 AC 47 ms
16,548 KB
testcase_17 AC 28 ms
7,676 KB
testcase_18 AC 108 ms
12,828 KB
testcase_19 AC 55 ms
11,820 KB
testcase_20 AC 27 ms
8,008 KB
testcase_21 AC 63 ms
19,580 KB
testcase_22 AC 64 ms
14,864 KB
testcase_23 AC 75 ms
10,072 KB
testcase_24 AC 7 ms
6,736 KB
testcase_25 AC 6 ms
6,760 KB
testcase_26 AC 4 ms
6,544 KB
testcase_27 AC 6 ms
6,716 KB
testcase_28 AC 8 ms
6,892 KB
testcase_29 AC 7 ms
7,032 KB
testcase_30 AC 6 ms
6,624 KB
testcase_31 AC 7 ms
6,672 KB
testcase_32 AC 5 ms
6,556 KB
testcase_33 AC 8 ms
6,716 KB
testcase_34 AC 7 ms
6,856 KB
testcase_35 AC 12 ms
7,060 KB
testcase_36 AC 11 ms
6,892 KB
testcase_37 AC 4 ms
6,556 KB
testcase_38 AC 8 ms
6,664 KB
testcase_39 AC 5 ms
6,600 KB
testcase_40 AC 5 ms
6,612 KB
testcase_41 AC 4 ms
6,784 KB
testcase_42 AC 7 ms
7,000 KB
testcase_43 AC 7 ms
6,928 KB
testcase_44 AC 8 ms
8,288 KB
testcase_45 AC 7 ms
8,848 KB
testcase_46 AC 8 ms
7,708 KB
testcase_47 AC 13 ms
9,148 KB
testcase_48 AC 19 ms
13,540 KB
testcase_49 AC 18 ms
10,384 KB
testcase_50 AC 36 ms
13,940 KB
testcase_51 AC 5 ms
6,628 KB
testcase_52 AC 38 ms
13,444 KB
testcase_53 AC 17 ms
10,688 KB
testcase_54 AC 5 ms
6,956 KB
testcase_55 AC 27 ms
12,828 KB
testcase_56 AC 8 ms
8,572 KB
testcase_57 AC 26 ms
10,136 KB
testcase_58 AC 18 ms
10,576 KB
testcase_59 AC 7 ms
7,308 KB
testcase_60 AC 8 ms
8,476 KB
testcase_61 AC 10 ms
7,504 KB
testcase_62 AC 18 ms
9,848 KB
testcase_63 AC 13 ms
7,988 KB
testcase_64 AC 142 ms
22,052 KB
testcase_65 AC 7 ms
7,020 KB
testcase_66 AC 59 ms
26,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
int n,s,t,k,m;
int x[1<<17];
vector<pair<int,int> >G[1<<17];
void solve()
{
	cin>>n>>s>>t>>k;
	s--,t--;
	k--;
	for(int i=0;i<n;i++)cin>>x[i];
	cin>>m;
	for(int i=0;i<m;i++)
	{
		int a,b,c;cin>>a>>b>>c;
		a--,b--;
		G[a].push_back(make_pair(b,c));
	}

        vector<vector<long> >dp(k+1,vector<long>(n,9e18));
	vector<vector<int> >prc(k+1,vector<int>(n,-1));
	vector<vector<int> >pru(k+1,vector<int>(n,-1));
	dp[0][s]=x[s];
	priority_queue<pair<long,pair<int,int> > >P;
	P.push(make_pair(-x[s],make_pair(0,s)));
	while(!P.empty())
	{
		int c=P.top().second.first;
		int u=P.top().second.second;
		long cost=-P.top().first;
		P.pop();
		if(dp[c][u]<cost)continue;
		for(pair<int,int>e:G[u])
		{
			int v=e.first;
			long nxt=cost+e.second+x[v];
			int nc=c==k?c:c+1;
			if(dp[nc][v]>nxt)
			{
				dp[nc][v]=nxt;
				prc[nc][v]=c;
				pru[nc][v]=u;
				P.push(make_pair(-nxt,make_pair(nc,v)));
			}
		}
	}

        if(dp[k][t]==(long)9e18)
	{
		cout<<"Impossible"<<endl;
		return ;
	}
	cout<<"Possible"<<endl;
	cout<<dp[k][t]<<endl;
	vector<int>ans;
	while(k!=-1)
	{
		ans.push_back(t);
		int nk=prc[k][t];
		t=pru[k][t];
		k=nk;
	}
	reverse(ans.begin(),ans.end());
	cout<<ans.size()<<endl;
	for(int i=0;i<ans.size();i++)cout<<ans[i]+1<<(i+1==ans.size()?"\n":" ");
    }
    int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        solve();
        return 0;
    }
0