QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#110697 | #6523. Escape Plan | hos_lyric | AC ✓ | 1008ms | 49848kb | C++14 | 2.6kb | 2023-06-03 12:55:44 | 2023-06-03 12:55:47 |
Judging History
answer
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
int N, M, K;
vector<int> E;
vector<int> D;
vector<int> A, B, W;
vector<vector<int>> G;
int main() {
for (int numCases; ~scanf("%d", &numCases); ) { for (int caseId = 1; caseId <= numCases; ++caseId) {
scanf("%d%d%d", &N, &M, &K);
E.resize(K);
for (int k = 0; k < K; ++k) {
scanf("%d", &E[k]);
--E[k];
}
D.resize(N);
for (int u = 0; u < N; ++u) {
scanf("%d", &D[u]);
}
A.resize(M);
B.resize(M);
W.resize(M);
for (int i = 0; i < M; ++i) {
scanf("%d%d%d", &A[i], &B[i], &W[i]);
--A[i];
--B[i];
}
G.assign(N, {});
for (int i = 0; i < M; ++i) {
G[A[i]].push_back(i);
G[B[i]].push_back(i);
}
using Entry = pair<int, int>;
priority_queue<Entry, vector<Entry>, greater<Entry>> que;
for (int k = 0; k < K; ++k) {
D[E[k]] = 0;
que.emplace(0, E[k]);
}
vector<int> dist(N, -1);
vector<int> cnt(N, 0);
for (; !que.empty(); ) {
const int c = que.top().first;
const int u = que.top().second;
que.pop();
if (++cnt[u] == D[u] + 1) {
dist[u] = c;
for (const int i : G[u]) {
const int cc = c + W[i];
const int v = A[i] ^ B[i] ^ u;
que.emplace(cc, v);
}
}
}
printf("%d\n", dist[0]);
}
#ifndef LOCAL
break;
#endif
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3656kb
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: 1008ms
memory: 49848kb
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