結果

問題 No.1545 [Cherry 2nd Tune N] Anthem
ユーザー abc3abc3
提出日時 2021-06-12 04:16:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,557 bytes
コンパイル時間 2,870 ms
コンパイル使用メモリ 222,320 KB
実行使用メモリ 59,944 KB
最終ジャッジ日時 2023-08-21 19:11:29
合計ジャッジ時間 22,893 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 56 ms
20,848 KB
testcase_05 AC 214 ms
59,944 KB
testcase_06 AC 69 ms
21,388 KB
testcase_07 AC 70 ms
17,240 KB
testcase_08 AC 207 ms
47,256 KB
testcase_09 AC 59 ms
16,032 KB
testcase_10 AC 46 ms
9,872 KB
testcase_11 AC 103 ms
28,652 KB
testcase_12 AC 184 ms
53,876 KB
testcase_13 AC 50 ms
14,760 KB
testcase_14 AC 65 ms
27,104 KB
testcase_15 AC 14 ms
5,724 KB
testcase_16 AC 87 ms
34,896 KB
testcase_17 AC 28 ms
5,676 KB
testcase_18 AC 133 ms
15,272 KB
testcase_19 AC 92 ms
24,496 KB
testcase_20 AC 49 ms
16,300 KB
testcase_21 AC 100 ms
32,864 KB
testcase_22 AC 86 ms
21,584 KB
testcase_23 AC 91 ms
14,216 KB
testcase_24 AC 9 ms
5,928 KB
testcase_25 AC 47 ms
7,496 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 19 ms
4,688 KB
testcase_28 AC 36 ms
9,844 KB
testcase_29 AC 20 ms
7,992 KB
testcase_30 AC 24 ms
7,756 KB
testcase_31 AC 34 ms
7,324 KB
testcase_32 AC 22 ms
5,156 KB
testcase_33 AC 41 ms
9,752 KB
testcase_34 AC 42 ms
8,096 KB
testcase_35 AC 185 ms
19,276 KB
testcase_36 AC 124 ms
15,600 KB
testcase_37 AC 5 ms
4,376 KB
testcase_38 AC 85 ms
10,096 KB
testcase_39 AC 11 ms
4,668 KB
testcase_40 AC 15 ms
5,492 KB
testcase_41 AC 5 ms
4,376 KB
testcase_42 AC 27 ms
7,048 KB
testcase_43 AC 26 ms
8,372 KB
testcase_44 AC 258 ms
5,620 KB
testcase_45 AC 5 ms
5,732 KB
testcase_46 AC 2,238 ms
6,808 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(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