結果

問題 No.1545 [Cherry 2nd Tune N] Anthem
ユーザー abc3abc3
提出日時 2021-06-12 04:12:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,581 bytes
コンパイル時間 2,464 ms
コンパイル使用メモリ 222,760 KB
実行使用メモリ 59,948 KB
最終ジャッジ日時 2023-08-21 18:46:02
合計ジャッジ時間 22,251 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 WA -
testcase_04 AC 56 ms
20,800 KB
testcase_05 AC 212 ms
59,948 KB
testcase_06 AC 67 ms
21,424 KB
testcase_07 AC 70 ms
17,200 KB
testcase_08 AC 202 ms
47,280 KB
testcase_09 AC 58 ms
15,884 KB
testcase_10 AC 45 ms
9,952 KB
testcase_11 AC 101 ms
28,768 KB
testcase_12 AC 171 ms
53,748 KB
testcase_13 AC 47 ms
14,844 KB
testcase_14 AC 61 ms
27,092 KB
testcase_15 AC 15 ms
5,772 KB
testcase_16 AC 87 ms
34,972 KB
testcase_17 AC 27 ms
5,644 KB
testcase_18 AC 139 ms
14,916 KB
testcase_19 AC 90 ms
24,548 KB
testcase_20 AC 48 ms
16,364 KB
testcase_21 AC 99 ms
32,840 KB
testcase_22 AC 88 ms
21,472 KB
testcase_23 AC 92 ms
14,044 KB
testcase_24 AC 10 ms
5,992 KB
testcase_25 AC 48 ms
7,512 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 18 ms
4,864 KB
testcase_28 AC 35 ms
9,704 KB
testcase_29 AC 20 ms
8,092 KB
testcase_30 AC 24 ms
7,696 KB
testcase_31 AC 33 ms
7,204 KB
testcase_32 AC 21 ms
5,224 KB
testcase_33 AC 41 ms
9,900 KB
testcase_34 AC 41 ms
7,964 KB
testcase_35 AC 181 ms
19,020 KB
testcase_36 AC 123 ms
15,412 KB
testcase_37 AC 6 ms
4,376 KB
testcase_38 AC 85 ms
10,152 KB
testcase_39 AC 11 ms
4,404 KB
testcase_40 AC 15 ms
5,568 KB
testcase_41 WA -
testcase_42 AC 26 ms
7,144 KB
testcase_43 AC 26 ms
8,504 KB
testcase_44 WA -
testcase_45 AC 5 ms
5,772 KB
testcase_46 AC 2,234 ms
6,828 KB
testcase_47 TLE -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
testcase_60 -- -
testcase_61 -- -
testcase_62 -- -
testcase_63 -- -
testcase_64 -- -
testcase_65 -- -
testcase_66 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

    #include <bits/stdc++.h>
    using namespace std;
    #include <math.h>
    #include <iomanip>
    #include <cstdint>
    #include <string>
    #include <sstream>
    template<class T> inline bool chmax(T& a, T b) { if (a <= b) { a = b; return 1; } return 0; }
    template<class T> inline bool chmin(T& a, T b) { if (a >= b) { a = b; return 1; } return 0; }
    #define rep(i,n) for (int i = 0; i < (n); ++i)
    typedef long long ll;
    using P=pair<ll,ll>;
    const ll INF=1e18;
    const int mod=998244353;
    
    struct edge{
        int to;
        ll w;
        edge(int to,ll w):to(to),w(w){}
    };
    
    void solve(){
        int n,s,t,k,m;
        cin>>n>>s>>t>>k;
        s--;t--;
        vector<int>x(n);
        rep(i,n){cin>>x[i];}
        cin>>m;
        vector<vector<edge>>G(n);
        rep(i,m){
            int a,b,y;
            cin>>a>>b>>y;a--;b--;
            rep(j,k){
                G[a].emplace_back(b,x[b]+y);
            }
        }

        vector<vector<ll>>dist(k+1,vector<ll>(n,INF));
        vector<vector<int>>prev(k+1,vector<int>(n,-1));
        vector<vector<int>>prec(k+1,vector<int>(n,-1));
        
        priority_queue<pair<ll,pair<int,int>>,vector<pair<ll,pair<int,int>>>,greater<pair<ll,pair<int,int>>>>q;
        q.push(make_pair(x[s],make_pair(0,s)));
        dist[0][s]=x[s];

        while(!q.empty()){
            int c=q.top().second.first;
            int v=q.top().second.second;
            ll cost=q.top().first;
            q.pop();
            if(cost!=dist[c][v]){continue;}
            for(auto u:G[v]){
                int nc=min(k-1,c+1);
                if(dist[nc][u.to]>cost+u.w){
                    dist[nc][u.to]=cost+u.w;
                    prev[nc][u.to]=v;
                    prec[nc][u.to]=c;
                    q.push(make_pair(dist[nc][u.to],make_pair(nc,u.to)));
                }
            }
        }

        if(dist[k-1][t]==INF){
            cout<<"Impossible"<<endl;
            return;
        }
        cout<<"Possible"<<endl;
        cout<<dist[k-1][t]<<endl;
        vector<int>ans;
        int p=t,pc=k-1;
        while(1){
            ans.push_back(p);
            if(p==s){break;}
            int np=pc;
            pc=prec[np][p];
            p=prev[np][p];
        }
        reverse(ans.begin(),ans.end());
        cout<<ans.size()<<endl;
        
        rep(i,ans.size()){
            printf("%d%c",ans[i]+1,(i+1<ans.size()?' ':'\n'));
        }
    }
    int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        solve();
        return 0;
    }
0