QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#137958 | #6523. Escape Plan | Yarema# | RE | 0ms | 17628kb | C++17 | 1.6kb | 2023-08-10 19:46:37 | 2023-08-10 19:46:39 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define FILL(a, b) memset(a, b, sizeof(a))
typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
const int N = 200447;
vector<pair<int, LL>> g[N];
multiset<LL> dis[N];
bool used[N];
int d[N];
void solve()
{
int n, m, k;
cin >> n >> m >> k;
set<pair<LL, int>> q;
FOR (i, 0, k)
{
int v;
cin >> v;
v--;
q.insert({0, v});
}
FOR (i, 0, n)
{
cin >> d[i];
}
FOR (i, 0, m)
{
int a, b, w;
cin >> a >> b >> w;
a--, b--;
g[a].PB({b, w});
g[b].PB({a, w});
}
LL ans = -1;
while (!q.empty())
{
int v = q.begin()->S;
LL D = q.begin()->F;
if (v == 0)
{
ans = D;
}
q.erase(q.begin());
assert(!used[v]);
used[v] = 1;
for (auto [to, w] : g[v])
{
if (used[to]) continue;
if (SZ(dis[to]) > d[to])
q.erase(MP(*dis[to].rbegin(), to));
dis[to].insert({D + w});
if (SZ(dis[to]) > d[to])
{
if (SZ(dis[to]) > d[to] + 1)
dis[to].erase(prev(dis[to].end()));
q.insert(MP(*dis[to].rbegin(), to));
}
}
}
cout << ans << '\n';
FOR (i, 0, n)
{
g[i].clear();
dis[i].clear();
used[i] = 0;
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--)
{
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 17628kb
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: -100
Dangerous Syscalls
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...