QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#139619 | #6523. Escape Plan | meomeo | AC ✓ | 610ms | 78100kb | C++14 | 1.8kb | 2023-08-14 04:21:39 | 2023-08-14 04:21:40 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
ios::sync_with_stdio(0); cin.tie(0);
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
int t;
cin >> t;
while (t--) {
int n, m, k;
cin >> n >> m >> k;
vector<vector<pair<int, int>>> a(n);
vector<int> exits(k);
for (int &u: exits) {
cin >> u;
u -= 1;
}
vector<int> d(n);
for (int &u: d) {
cin >> u;
}
for (int i = 0 ; i < m ; i++) {
int u, v, w;
cin >> u >> v >> w;
u -= 1, v -= 1;
a[u].push_back({w, v});
a[v].push_back({w, u});
}
for (int &u: exits) {
d[u] = 0;
}
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
for (int &u: exits) {
pq.push({0, u});
}
vector<int> dist(n, 1E18);
vector<int> vis(n);
for (int &u: exits) {
dist[u] = 0;
}
while (pq.size()) {
int u = pq.top().second;
int du = pq.top().first;
pq.pop();
if (d[u]) {
d[u] -= 1;
continue;
}
if (vis[u]) {
continue;
}
vis[u] = 1;
dist[u] = du;
for (auto &[w, v]: a[u]) {
if (dist[u] + w < dist[v]) {
pq.push({dist[u] + w, v});
}
}
}
if (dist[0] == 1E18) {
cout << -1 << "\n";
}
else {
cout << dist[0] << "\n";
}
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3472kb
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: 610ms
memory: 78100kb
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