結果

問題 No.1545 [Cherry 2nd Tune N] Anthem
ユーザー 👑 potato167potato167
提出日時 2021-06-11 23:52:12
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 540 ms / 3,000 ms
コード長 2,805 bytes
コンパイル時間 2,682 ms
コンパイル使用メモリ 214,176 KB
実行使用メモリ 72,212 KB
最終ジャッジ日時 2023-08-21 15:03:35
合計ジャッジ時間 19,284 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 105 ms
26,804 KB
testcase_05 AC 540 ms
72,212 KB
testcase_06 AC 119 ms
25,796 KB
testcase_07 AC 100 ms
21,340 KB
testcase_08 AC 289 ms
49,108 KB
testcase_09 AC 67 ms
16,092 KB
testcase_10 AC 43 ms
8,372 KB
testcase_11 AC 186 ms
35,980 KB
testcase_12 AC 365 ms
59,592 KB
testcase_13 AC 66 ms
15,864 KB
testcase_14 AC 120 ms
29,500 KB
testcase_15 AC 16 ms
5,732 KB
testcase_16 AC 190 ms
40,964 KB
testcase_17 AC 30 ms
5,504 KB
testcase_18 AC 126 ms
13,600 KB
testcase_19 AC 144 ms
26,096 KB
testcase_20 AC 56 ms
16,320 KB
testcase_21 AC 249 ms
49,476 KB
testcase_22 AC 114 ms
23,236 KB
testcase_23 AC 101 ms
14,228 KB
testcase_24 AC 10 ms
6,748 KB
testcase_25 AC 13 ms
8,656 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 8 ms
5,128 KB
testcase_28 AC 17 ms
10,460 KB
testcase_29 AC 15 ms
9,696 KB
testcase_30 AC 11 ms
7,280 KB
testcase_31 AC 14 ms
7,944 KB
testcase_32 AC 7 ms
5,436 KB
testcase_33 AC 18 ms
10,480 KB
testcase_34 AC 14 ms
8,768 KB
testcase_35 AC 50 ms
26,112 KB
testcase_36 AC 37 ms
20,024 KB
testcase_37 AC 4 ms
4,376 KB
testcase_38 AC 19 ms
10,476 KB
testcase_39 AC 5 ms
4,580 KB
testcase_40 AC 8 ms
6,100 KB
testcase_41 AC 3 ms
4,380 KB
testcase_42 AC 13 ms
7,364 KB
testcase_43 AC 14 ms
8,664 KB
testcase_44 AC 4 ms
4,380 KB
testcase_45 AC 4 ms
6,428 KB
testcase_46 AC 18 ms
8,392 KB
testcase_47 AC 31 ms
12,944 KB
testcase_48 AC 38 ms
21,024 KB
testcase_49 AC 56 ms
20,636 KB
testcase_50 AC 103 ms
33,072 KB
testcase_51 AC 6 ms
4,688 KB
testcase_52 AC 139 ms
43,904 KB
testcase_53 AC 46 ms
18,896 KB
testcase_54 AC 8 ms
5,776 KB
testcase_55 AC 99 ms
34,192 KB
testcase_56 AC 4 ms
4,380 KB
testcase_57 AC 82 ms
26,888 KB
testcase_58 AC 56 ms
21,896 KB
testcase_59 AC 10 ms
5,668 KB
testcase_60 AC 9 ms
7,144 KB
testcase_61 AC 23 ms
10,184 KB
testcase_62 AC 64 ms
22,540 KB
testcase_63 AC 32 ms
12,332 KB
testcase_64 AC 256 ms
64,512 KB
testcase_65 AC 10 ms
5,376 KB
testcase_66 AC 152 ms
69,080 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using ll=long long;
using ld=long double;
ll I=1167167167167167167;
ll Q=1e9+7;
#define rep(i,a) for (ll i=0;i<a;i++)
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});}
template<class T> void print_tate(vector<T> &v) {rep(i,v.size()) cout<<v[i]<<"\n";}
void yneos(bool a){if(a) cout<<"Yes"<<"\n"; else cout<<"No"<<"\n";}
ll N,S,T,K;
ll p[111111];

int where[1234567];

using len_type=ll;
struct edge{
    ll to;
	len_type length;
};

len_type dijkstra_movement(edge e,int from,len_type t){
    return t+p[e.to%N]+e.length;
}

//距離INF=1167167167167167167
vector<len_type> dijkstra(vector<vector<edge>> &G,int start){
    int M=G.size();
    assert(M>start&&start>=0);
    vector<len_type> seen(M,1167167167167167167);
    seen[start]=0;
    priority_queue<pair<len_type,int>,vector<pair<len_type,int>>,greater<pair<len_type,int>>> pq;
    pq.push({0,start});
    while(!pq.empty()){
        len_type time;
        int ver;
        tie(time,ver)=pq.top();
        pq.pop();
        if(seen[ver]<time) continue;
        for(edge x:G[ver]){
            len_type T=dijkstra_movement(x,ver,time);
            if(T<seen[x.to]){
				where[x.to]=ver;
                pq.push({T,x.to});
                seen[x.to]=T;
            }
        }
    }
    return seen;
}

//おちこんだりもしたけれど、私はげんきです。
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin>>N>>S>>T>>K;
	S--,T--;
	rep(i,N) cin>>p[i];
	vector<vector<edge>> G(N*(K));
	int M;
	cin>>M;
	rep(i,M){
		ll a,b;
		ll y;
		cin>>a>>b>>y;
		a--,b--;
		G[a+N*(K-1)].push_back({b+N*(K-1),y});
		//G[b+N*(K-1)].push_back({a+N*(K-1),y});
		rep(i,K-1){
			G[a+N*(i)].push_back({b+N*(i+1),y});
			//G[b+N*(i)].push_back({a+N*(i+1),y});
		}
	}
	auto seen=dijkstra(G,S);
	//rep(i,N*K) cout<<seen[i]<<endl;
	if(seen[N*(K-1)+T]==I){
		cout<<"Impossible\n";
		return 0;
	}
	int A=N*(K-1)+T;
	cout<<"Possible\n";
	cout<<seen[A]+p[S]<<"\n";
	vector<int> ans={A};
	while(A!=S){
		ans.push_back(where[A]);
		A=where[A];
	}
	int siz=ans.size();
	cout<<siz<<"\n";
	for(int i=siz-1;i>=0;i--){
		cout<<ans[i]%N+1;
		if(i!=0) cout<<" ";
	}
	cout<<"\n";
	return 0;
}
0