結果

問題 No.1545 [Cherry 2nd Tune N] Anthem
ユーザー KudeKude
提出日時 2021-06-11 22:41:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 286 ms / 3,000 ms
コード長 2,643 bytes
コンパイル時間 4,559 ms
コンパイル使用メモリ 272,556 KB
実行使用メモリ 70,604 KB
最終ジャッジ日時 2023-08-21 13:25:33
合計ジャッジ時間 18,396 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 76 ms
24,776 KB
testcase_05 AC 286 ms
53,344 KB
testcase_06 AC 97 ms
21,396 KB
testcase_07 AC 82 ms
19,648 KB
testcase_08 AC 223 ms
31,092 KB
testcase_09 AC 57 ms
10,348 KB
testcase_10 AC 42 ms
7,896 KB
testcase_11 AC 141 ms
29,188 KB
testcase_12 AC 236 ms
45,452 KB
testcase_13 AC 61 ms
14,340 KB
testcase_14 AC 83 ms
28,172 KB
testcase_15 AC 15 ms
5,408 KB
testcase_16 AC 117 ms
38,276 KB
testcase_17 AC 26 ms
4,692 KB
testcase_18 AC 113 ms
11,468 KB
testcase_19 AC 110 ms
20,924 KB
testcase_20 AC 44 ms
10,608 KB
testcase_21 AC 141 ms
46,520 KB
testcase_22 AC 91 ms
22,976 KB
testcase_23 AC 87 ms
9,964 KB
testcase_24 AC 7 ms
5,176 KB
testcase_25 AC 9 ms
6,280 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 7 ms
4,376 KB
testcase_28 AC 12 ms
7,252 KB
testcase_29 AC 10 ms
6,680 KB
testcase_30 AC 8 ms
5,532 KB
testcase_31 AC 11 ms
5,912 KB
testcase_32 AC 5 ms
4,696 KB
testcase_33 AC 12 ms
7,020 KB
testcase_34 AC 10 ms
6,116 KB
testcase_35 AC 32 ms
15,016 KB
testcase_36 AC 23 ms
11,924 KB
testcase_37 AC 3 ms
4,380 KB
testcase_38 AC 12 ms
7,096 KB
testcase_39 AC 4 ms
4,380 KB
testcase_40 AC 6 ms
4,868 KB
testcase_41 AC 3 ms
4,376 KB
testcase_42 AC 9 ms
5,556 KB
testcase_43 AC 10 ms
6,260 KB
testcase_44 AC 3 ms
4,380 KB
testcase_45 AC 5 ms
6,748 KB
testcase_46 AC 12 ms
6,944 KB
testcase_47 AC 21 ms
10,052 KB
testcase_48 AC 29 ms
19,600 KB
testcase_49 AC 36 ms
15,024 KB
testcase_50 AC 72 ms
24,716 KB
testcase_51 AC 4 ms
4,380 KB
testcase_52 AC 90 ms
29,588 KB
testcase_53 AC 31 ms
14,128 KB
testcase_54 AC 6 ms
4,636 KB
testcase_55 AC 62 ms
23,776 KB
testcase_56 AC 4 ms
4,380 KB
testcase_57 AC 61 ms
18,852 KB
testcase_58 AC 36 ms
15,536 KB
testcase_59 AC 7 ms
5,308 KB
testcase_60 AC 8 ms
6,584 KB
testcase_61 AC 15 ms
7,820 KB
testcase_62 AC 41 ms
15,740 KB
testcase_63 AC 22 ms
9,172 KB
testcase_64 AC 209 ms
49,004 KB
testcase_65 AC 7 ms
4,844 KB
testcase_66 AC 131 ms
70,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i,n)for (int i = 0; i < int(n); ++i)
#define rrep(i,n)for (int i = int(n)-1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
template<class T> void chmax(T& a, const T& b) {a = max(a, b);}
template<class T> void chmin(T& a, const T& b) {a = min(a, b);}
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

const unsigned long long INF = 1002003004005006007;
template<class T>
std::pair<std::vector<unsigned long long>, std::vector<int>> dijkstra(std::vector<std::vector<std::pair<int,T>>>& to, int s=0) {
    struct QueElem {
        int v;
        unsigned long long c;
        bool operator<(const QueElem a) const {return c > a.c;}
        QueElem(int v, unsigned long long c): v(v), c(c) {}
    };
    std::pair<std::vector<unsigned long long>, std::vector<int>> res;
    std::vector<unsigned long long>& dist = res.first;
    std::vector<int>& pre = res.second;
    dist.resize(to.size(), INF);
    pre.resize(to.size(), -1);
    std::priority_queue<QueElem> q;
    dist[s] = 0;
    pre[s] = -1;
    q.emplace(s, 0);
    while(!q.empty()) {
        QueElem qe = q.top(); q.pop();
        int u = qe.v;
        unsigned long long c = qe.c;
        if (c > dist[u]) continue;
        for(auto vc: to[u]) {
            int v = vc.first;
            unsigned long long nc = c + vc.second;
            if (nc < dist[v]) {
                dist[v] = nc;
                pre[v] = u;
                q.emplace(v, nc);
            }
        }
    }
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, s, t, k;
    cin >> n >> s >> t >> k;
    s--, t--; k--;
    VI x(n);
    rep(i, n) cin >> x[i];
    int m;
    cin >> m;
    vector<vector<P>> to(n * (k + 1));
    rep(_, m) {
        int a, b, y;
        cin >> a >> b >> y;
        --a, --b;
        rep(j, k) {
            to[(k + 1) * a + j].emplace_back((k + 1) * b + j + 1, y + x[b]);
        }
        to[(k + 1) * a + k].emplace_back((k + 1) * b + k, y + x[b]);
    }
    auto [dist, pre] = dijkstra(to, (k + 1) * s);
    if (dist[(k + 1) * t + k] == INF) {
        cout << "Impossible" << '\n';
        return 0;
    }
    cout << "Possible" << '\n';
    cout << x[s] + dist[(k + 1) * t + k] << '\n';
    VI ps;
    for(int v = (k + 1) * t + k; v != -1; v = pre[v]) {
        ps.push_back(v / (k + 1));
    }
    int sz = ps.size();
    cout << sz << '\n';
    rrep(i, sz) cout << ps[i] + 1 << " \n"[i == 0];
}
0