結果

問題 No.1545 [Cherry 2nd Tune N] Anthem
ユーザー suzuken_w
提出日時 2021-06-12 04:06:35
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 343 ms / 3,000 ms
コード長 2,262 bytes
コンパイル時間 3,409 ms
コンパイル使用メモリ 236,484 KB
最終ジャッジ日時 2025-01-22 07:41:20
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 67
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>;
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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; }
template<class T>void debag(const vector<T> &a){cerr<<"debag :";for(auto v:a)cerr<<v<<" ";cerr<<"\n";}
template<class T>void print(const vector<T> &a){for(auto v:a)cout<<v<<" ";cout<<"\n";}
using tp=tuple<ll,int,int>;
int main(){
int n,s,t,k;
cin>>n>>s>>t>>k;
s--;t--;
V<ll> x(n);
for(int i=0;i<n;i++)cin>>x[i];
V<V<P>> dp(k+1,V<P>(n+5,P{inf,inf}));
ll m;
cin>>m;
V<V<P>> g(n);
map<P,ll> mp;
for(int i=0;i<m;i++){
ll a,b,c;
cin>>a>>b>>c;
--a;--b;
g[a].emplace_back(b,c);
mp[{a,b}]=c;
}
dp[1][s]=P(x[s],-1);
priority_queue<tp,V<tp>,greater<tp>> pq;
pq.emplace(dp[1][s].fi,1,s);
while(pq.size()){
auto [v,tim,cur]=pq.top();
pq.pop();
if(dp[tim][cur].fi<v)continue;
for(auto &[to,cost]:g[cur]){
P nxt={cost+x[to]+v,cur};
if(chmin(dp[min(k,tim+1)][to],nxt)){
pq.emplace(nxt.fi,min(k,tim+1),to);
}
}
}
if(dp[k][t].fi>=inf){
cout<<"Impossible"<<"\n";
return 0;
}
int cur=t,id=k;
V<int> ans;
while(cur!=-1){
ans.emplace_back(cur+1);
int bfo=cur;
cur=dp[id][cur].se;
if(cur==-1)break;
if(id!=k||dp[id][bfo].fi!=dp[id][cur].fi+x[bfo]+mp[{cur,bfo}]){
id--;
}
}
cout<<"Possible"<<"\n";
cout<<dp[k][t].fi<<"\n";
cout<<ans.size()<<"\n";
reverse(all(ans));
print(ans);
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0