QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#719876 | #6523. Escape Plan | QOJ114514ancestor# | AC ✓ | 902ms | 71324kb | C++14 | 1.5kb | 2024-11-07 09:33:03 | 2024-11-07 09:33:03 |
Judging History
answer
#include<bits/stdc++.h>
# define int long long
# define rep(i, j, k) for (int i = j; i <= k; ++i)
# define inf 10000000000000000LL
using namespace std;
int T, n, m, k, d[100005], res[100005], hd[100005], to[2000005], nxt[2000005], w[2000005], etimer;
int ok[100005];
struct node
{
int u, dis;
bool operator<(const node &x)const{return dis > x.dis;}
};
priority_queue < node > q;
priority_queue < int > dq[100005];
void addedge(int u, int v, int we){to[++etimer] = v, nxt[etimer] = hd[u], hd[u] = etimer; w[etimer] = we;}
void dijkstra()
{
while (!q.empty())
{
int u = q.top().u; if (ok[u]) {q.pop(); continue;} d[u] = q.top().dis, q.pop(); ok[u] = 1;
// cerr << u << endl;
for (int i = hd[u]; i; i = nxt[i]) {dq[to[i]].push(d[u] + w[i]); if (--res[to[i]] <= -2) ++res[to[i]], dq[to[i]].pop(); if (res[to[i]] <= -1) q.push({to[i], dq[to[i]].top()});}
}
}
signed main()
{
ios::sync_with_stdio(false); cin.tie(0), cout.tie(0);
cin >> T;
while (T--)
{
cin >> n >> m >> k;
memset(hd, 0, sizeof(hd)), memset(to, 0, sizeof(to)), memset(nxt, 0, sizeof(nxt)), memset(ok, 0, sizeof(ok)), etimer = 0;
rep(i, 1, n) d[i] = inf;
rep(i, 1, n) while (!dq[i].empty()) dq[i].pop();
rep(i, 1, k) {int x; cin >> x; d[x] = 0, q.push({x, 0}), dq[x].push(0);}
rep(i, 1, n) cin >> res[i];
rep(i, 1, m) {int u, v, w; cin >> u >> v >> w; addedge(u, v, w), addedge(v, u, w);}
dijkstra();
cout << (d[1] == inf ? -1LL : d[1]) << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 40804kb
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: 902ms
memory: 71324kb
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