QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#304701#6523. Escape Planucup-team2894#AC ✓523ms67104kbC++172.5kb2024-01-14 00:36:372024-01-14 00:36:38

Judging History

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

  • [2024-01-14 00:36:38]
  • 评测
  • 测评结果:AC
  • 用时:523ms
  • 内存:67104kb
  • [2024-01-14 00:36:37]
  • 提交

answer

#include <bits/stdc++.h>
#define fr first
#define sc second
#define all(a) (a).begin(), (a).end()
#define unique(a) a.resize(unique(a.begin(), a.end()) - a.begin())

using namespace std;

#ifdef ONPC
mt19937 rnd(223);
#else
mt19937 rnd(chrono::high_resolution_clock::now()
			.time_since_epoch().count());
#endif

#define TIME (clock() * 1.0 / CLOCKS_PER_SEC)

using ll = long long;
using ld = double;

const int maxn = 1e5 + 100, inf = 1e9 + 100;
const long long oo = LLONG_MAX / 2;

void solve() {
    int N, M, K;
    cin >> N >> M >> K;
    vector<int> exit_city;
    for (int i = 1; i <= K; i++) {
        int n;
        cin >> n;
        exit_city.push_back(n);
    }
    vector<int> num_monster(N + 5);
    for (int i = 1; i <= N; i++) {
        cin >> num_monster[i];
    }
    vector<vector<pair<int, long long>>> graph(N + 5);
    for (int i = 1; i <= M; i++) {
        int a, b, w;
        cin >> a >> b >> w;
        graph[a].emplace_back(b, w);
        graph[b].emplace_back(a, w);
    }
    vector<priority_queue<long long>> node_pq(N + 5);
    priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> pq;
    vector<long long> dist(N + 5, oo);
    for (int n : exit_city) {
        num_monster[n] = 0;
        dist[n] = 0;
        node_pq[n].push(0);
        pq.push(make_pair(0, n));
    }
    while(pq.size()) {
        auto p = pq.top();
        pq.pop();
        if (p.first != dist[p.second]) {
            continue;
        }
        int n = p.second;
//        cout << n << " " << dist[n] << "\n";
        for (auto e : graph[n]) {
//            cout << "edge: " << e.first << " " << e.second << "\n";

            node_pq[e.first].push(dist[n] + e.second);
            while(node_pq[e.first].size() > num_monster[e.first] + 1) {
                node_pq[e.first].pop();
            }
            if (node_pq[e.first].size() == num_monster[e.first] + 1 && node_pq[e.first].top() < dist[e.first]) {
                dist[e.first] = node_pq[e.first].top();
                pq.push(make_pair(dist[e.first], e.first));
            }
        }
    }
    cout << (dist[1] == oo ? -1 : dist[1]) << "\n";
}

int main() {
#ifdef ONPC
    freopen("../a.in", "r", stdin);
//    freopen("../a.out", "w", stdout);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout << fixed;
    cout.precision(20);
    int T;
    cin >> T;
    while(T--) {
        solve();
    }
    cerr << "\n\nConsumed " << TIME << endl;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 523ms
memory: 67104kb

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