QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#368795 | #6523. Escape Plan | kabuu | AC ✓ | 433ms | 44500kb | C++20 | 1.8kb | 2024-03-27 16:32:07 | 2024-03-27 16:32:07 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
typedef pair<ll, ll> PII;
const ll mod = 998244353;
const ll N = 1e5 + 100;
const ll inf = 0x3f3f3f3f;
priority_queue<ll> in[N];
ll d[N];
int a[N];
void solve()
{
int n, m, k;
cin >> n >> m >> k;
for (int i = 1; i <= n; i++) {
d[i] = 1e18;
while (in[i].size())
in[i].pop();
}
priority_queue<PII, vector<PII>, greater<PII>> q;
vector<bool> dist(n + 1);
for (int i = 1; i <= k; i++) {
int x;
cin >> x;
d[x] = 0;
q.push({ 0, x });
}
vector<vector<pair<int, int>>> g(n + 1);
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= m; i++) {
int x, y;
ll w;
cin >> x >> y >> w;
g[x].push_back({ y, w });
g[y].push_back({ x, w });
}
while (q.size()) {
auto to = q.top();
q.pop();
int now = to.second;
if (dist[now])
continue;
dist[now] = true;
for (auto x : g[now]) {
int v = x.first, dis = x.second;
// if (dist[v])
// continue;
in[v].push(d[now] + dis);
if (in[v].size() > a[v] + 1)
in[v].pop();
if (in[v].size() == a[v] + 1 && d[v] > in[v].top()) {
d[v] = in[v].top();
q.push({ d[v], v });
}
}
}
if (d[1] == 1e18) {
cout << -1 << endl;
} else {
cout << d[1] << endl;
}
}
/*
*/
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int _ = 1;
cin >> _;
while (_--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 6856kb
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: 433ms
memory: 44500kb
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