結果

問題 No.1545 [Cherry 2nd Tune N] Anthem
ユーザー 👑 potato167potato167
提出日時 2021-06-11 23:52:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 564 ms / 3,000 ms
コード長 2,805 bytes
コンパイル時間 2,768 ms
コンパイル使用メモリ 216,784 KB
実行使用メモリ 70,528 KB
最終ジャッジ日時 2024-05-08 20:31:34
合計ジャッジ時間 15,243 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 108 ms
27,008 KB
testcase_05 AC 564 ms
70,528 KB
testcase_06 AC 132 ms
25,856 KB
testcase_07 AC 101 ms
21,504 KB
testcase_08 AC 294 ms
49,516 KB
testcase_09 AC 65 ms
16,256 KB
testcase_10 AC 43 ms
8,448 KB
testcase_11 AC 200 ms
36,224 KB
testcase_12 AC 393 ms
57,600 KB
testcase_13 AC 67 ms
16,000 KB
testcase_14 AC 120 ms
29,440 KB
testcase_15 AC 15 ms
5,760 KB
testcase_16 AC 209 ms
40,960 KB
testcase_17 AC 28 ms
5,376 KB
testcase_18 AC 114 ms
13,568 KB
testcase_19 AC 139 ms
26,112 KB
testcase_20 AC 53 ms
16,384 KB
testcase_21 AC 246 ms
47,744 KB
testcase_22 AC 97 ms
23,424 KB
testcase_23 AC 91 ms
14,080 KB
testcase_24 AC 10 ms
6,656 KB
testcase_25 AC 13 ms
8,832 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 9 ms
5,376 KB
testcase_28 AC 17 ms
10,496 KB
testcase_29 AC 14 ms
9,472 KB
testcase_30 AC 11 ms
7,424 KB
testcase_31 AC 17 ms
8,112 KB
testcase_32 AC 7 ms
5,376 KB
testcase_33 AC 20 ms
10,368 KB
testcase_34 AC 15 ms
8,532 KB
testcase_35 AC 51 ms
26,112 KB
testcase_36 AC 37 ms
19,968 KB
testcase_37 AC 5 ms
5,376 KB
testcase_38 AC 18 ms
10,368 KB
testcase_39 AC 5 ms
5,376 KB
testcase_40 AC 9 ms
6,144 KB
testcase_41 AC 3 ms
5,376 KB
testcase_42 AC 12 ms
7,424 KB
testcase_43 AC 15 ms
8,704 KB
testcase_44 AC 4 ms
5,376 KB
testcase_45 AC 5 ms
6,656 KB
testcase_46 AC 18 ms
8,704 KB
testcase_47 AC 30 ms
13,056 KB
testcase_48 AC 39 ms
21,120 KB
testcase_49 AC 56 ms
20,608 KB
testcase_50 AC 106 ms
33,152 KB
testcase_51 AC 6 ms
5,376 KB
testcase_52 AC 145 ms
44,032 KB
testcase_53 AC 46 ms
19,072 KB
testcase_54 AC 9 ms
5,504 KB
testcase_55 AC 99 ms
34,304 KB
testcase_56 AC 5 ms
5,376 KB
testcase_57 AC 81 ms
26,880 KB
testcase_58 AC 57 ms
22,016 KB
testcase_59 AC 9 ms
5,888 KB
testcase_60 AC 10 ms
7,168 KB
testcase_61 AC 22 ms
10,240 KB
testcase_62 AC 64 ms
22,528 KB
testcase_63 AC 32 ms
12,288 KB
testcase_64 AC 269 ms
63,340 KB
testcase_65 AC 10 ms
5,376 KB
testcase_66 AC 167 ms
67,584 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