結果
問題 | No.1545 [Cherry 2nd Tune N] Anthem |
ユーザー |
👑 ![]() |
提出日時 | 2021-06-11 23:52:12 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 590 ms / 3,000 ms |
コード長 | 2,805 bytes |
コンパイル時間 | 2,426 ms |
コンパイル使用メモリ | 209,320 KB |
最終ジャッジ日時 | 2025-01-22 07:18:48 |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 67 |
ソースコード
#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=1167167167167167167vector<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;}