結果

問題 No.1545 [Cherry 2nd Tune N] Anthem
ユーザー abc3abc3
提出日時 2021-06-12 05:05:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,497 bytes
コンパイル時間 2,499 ms
コンパイル使用メモリ 221,724 KB
実行使用メモリ 60,024 KB
最終ジャッジ日時 2023-08-21 23:39:56
合計ジャッジ時間 24,050 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 54 ms
20,988 KB
testcase_05 AC 191 ms
60,024 KB
testcase_06 AC 69 ms
21,412 KB
testcase_07 AC 67 ms
17,236 KB
testcase_08 AC 194 ms
47,296 KB
testcase_09 AC 56 ms
15,916 KB
testcase_10 AC 44 ms
9,956 KB
testcase_11 AC 100 ms
28,848 KB
testcase_12 AC 165 ms
53,920 KB
testcase_13 AC 47 ms
14,712 KB
testcase_14 AC 61 ms
27,108 KB
testcase_15 AC 14 ms
5,788 KB
testcase_16 AC 83 ms
34,984 KB
testcase_17 AC 27 ms
5,684 KB
testcase_18 AC 121 ms
14,956 KB
testcase_19 AC 87 ms
24,592 KB
testcase_20 AC 48 ms
16,364 KB
testcase_21 AC 95 ms
32,964 KB
testcase_22 AC 87 ms
21,584 KB
testcase_23 AC 88 ms
14,156 KB
testcase_24 AC 10 ms
5,928 KB
testcase_25 AC 54 ms
7,644 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 21 ms
4,904 KB
testcase_28 AC 39 ms
9,676 KB
testcase_29 AC 21 ms
8,160 KB
testcase_30 AC 27 ms
7,856 KB
testcase_31 AC 37 ms
7,208 KB
testcase_32 AC 24 ms
5,180 KB
testcase_33 AC 46 ms
9,752 KB
testcase_34 AC 47 ms
8,076 KB
testcase_35 AC 206 ms
19,284 KB
testcase_36 AC 143 ms
15,480 KB
testcase_37 AC 7 ms
4,380 KB
testcase_38 AC 98 ms
10,080 KB
testcase_39 AC 12 ms
4,416 KB
testcase_40 AC 16 ms
5,412 KB
testcase_41 AC 5 ms
4,376 KB
testcase_42 AC 29 ms
7,084 KB
testcase_43 AC 29 ms
8,304 KB
testcase_44 AC 305 ms
5,724 KB
testcase_45 AC 5 ms
5,752 KB
testcase_46 AC 2,663 ms
6,888 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>>>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(pc!=-1){
            ans.push_back(p);
            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