QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#134467#6523. Escape PlanrniyaAC ✓448ms44256kbC++172.2kb2023-08-03 20:26:492023-08-03 20:26:53

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-03 20:26:53]
  • 评测
  • 测评结果:AC
  • 用时:448ms
  • 内存:44256kb
  • [2023-08-03 20:26:49]
  • 提交

answer

#include <bits/stdc++.h>
#ifdef LOCAL
#include <debug.hpp>
#else
#define debug(...) void(0)
#endif

using namespace std;

typedef long long ll;
#define all(x) begin(x), end(x)
constexpr int INF = (1 << 30) - 1;
constexpr long long IINF = (1LL << 60) - 1;
constexpr int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

template <class T> istream& operator>>(istream& is, vector<T>& v) {
    for (auto& x : v) is >> x;
    return is;
}

template <class T> ostream& operator<<(ostream& os, const vector<T>& v) {
    auto sep = "";
    for (const auto& x : v) os << exchange(sep, " ") << x;
    return os;
}

template <class T, class U = T> bool chmin(T& x, U&& y) { return y < x and (x = forward<U>(y), true); }

template <class T, class U = T> bool chmax(T& x, U&& y) { return x < y and (x = forward<U>(y), true); }

template <class T> void mkuni(vector<T>& v) {
    sort(begin(v), end(v));
    v.erase(unique(begin(v), end(v)), end(v));
}

template <class T> int lwb(const vector<T>& v, const T& x) { return lower_bound(begin(v), end(v), x) - begin(v); }

void solve() {
    int n, m, K;
    cin >> n >> m >> K;
    vector<int> e(K), d(n);
    for (int& x : e) cin >> x, x--;
    for (int& x : d) cin >> x;
    vector<vector<pair<int, int>>> G(n);
    for (; m--;) {
        int x, y, w;
        cin >> x >> y >> w;
        x--, y--;
        G[x].emplace_back(y, w);
        G[y].emplace_back(x, w);
    }

    vector<ll> dp(n, IINF);
    vector<priority_queue<ll>> nxt(n);
    priority_queue<pair<ll, int>> pq;
    for (int& x : e) {
        dp[x] = 0;
        pq.emplace(-dp[x], x);
    }

    while (not pq.empty()) {
        auto [val, v] = pq.top();
        pq.pop();
        val *= -1;
        if (dp[v] < val) continue;
        for (auto [u, cost] : G[v]) {
            nxt[u].emplace(val + cost);
            while (int(nxt[u].size()) > d[u] + 1) nxt[u].pop();
            if (int(nxt[u].size()) > d[u] and chmin(dp[u], nxt[u].top())) {
                pq.emplace(-dp[u], u);
            }
        }
    }

    ll ans = dp[0];
    cout << (ans == IINF ? -1 : ans) << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    cin >> T;
    for (; T--;) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3540kb

input:

2
3 4 1
3
1 1 1
1 2 1
1 2 2
2 3 1
2 3 2
3 2 2
2 3
2 0 0
1 2 1
1 3 1

output:

4
-1

result:

ok 2 number(s): "4 -1"

Test #2:

score: 0
Accepted
time: 448ms
memory: 44256kb

input:

100
100 1808 2
94 47
3 3 0 2 4 3 3 4 0 0 2 2 2 3 2 4 0 2 3 4 4 2 0 3 4 3 1 0 2 1 2 2 0 3 4 4 4 1 2 2 3 1 0 0 3 1 4 2 1 3 3 4 3 0 4 1 0 3 2 1 4 4 1 3 2 3 3 3 3 1 0 3 0 4 3 1 0 4 0 4 4 1 2 0 0 4 1 3 3 3 0 2 2 1 1 2 3 4 1 2
72 29 1138
59 78 2398
95 5 1610
32 46 4176
36 99 8143
100 69 413
61 58 1595
9 9...

output:

5109
1021
3293
4646
3796
3394
1884
6772
2329
2067
3296
2809
865
4249
2241
3792
2135
2544
3343
1775
10602
4677
1700
2150
7071
14055
3368
2322
1113
1980
3067
1617
1702
-1
2879
6265
2065
2810
2289
3001
402
3769
18118
6874
7879
3823
-1
510
2636
10564
-1
3166
3615
7526
5549
1261
3302
270
4440
1998
3350
3...

result:

ok 100 numbers