QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#234148 | #6523. Escape Plan | ucup-team1198# | AC ✓ | 1517ms | 135836kb | C++20 | 2.0kb | 2023-11-01 14:32:58 | 2023-11-01 14:33:00 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define ld long double
#define all(a) (a).begin(), (a).end()
const int MAXN = 100'100;
vector<pair<int, int>> G[MAXN];
const long long INF = 1e18;
multiset<long long> d_mins[MAXN];
multiset<long long> others[MAXN];
void solve() {
int n, m, k;
cin >> n >> m >> k;
vector<int> e(k);
for (int i = 0; i < k; ++i) {
cin >> e[i];
--e[i];
}
vector<int> d(n);
for (int i = 0; i < n; ++i) {
cin >> d[i];
}
for (int i = 0; i < m; ++i) {
int x, y, w;
cin >> x >> y >> w;
--x;
--y;
G[x].emplace_back(y, w);
G[y].emplace_back(x, w);
}
vector<long long> dist(n, INF);
vector<bool> alive(n, true);
set<pair<long long, int>> Q;
auto add_val = [&](int i, long long x) {
if (d_mins[i].size() < d[i]) {
d_mins[i].emplace(x);
} else if (d[i] > 0 && *d_mins[i].rbegin() > x) {
d_mins[i].emplace(x);
others[i].emplace(*(--d_mins[i].end()));
d_mins[i].erase(--d_mins[i].end());
} else {
others[i].emplace(x);
}
if (alive[i] && !others[i].empty() && dist[i] > *others[i].begin()) {
Q.erase(make_pair(dist[i], i));
dist[i] = *others[i].begin();
Q.emplace(dist[i], i);
}
};
for (int v : e) {
dist[v] = 0;
Q.emplace(0, v);
}
while (!Q.empty()) {
int v = Q.begin()->second;
Q.erase(Q.begin());
alive[v] = false;
for (auto [u, w] : G[v]) {
add_val(u, dist[v] + w);
}
}
if (dist[0] == INF)
cout << -1 << '\n';
else
cout << dist[0] << '\n';
for (int i = 0; i < n; ++i) {
G[i].clear();
d_mins[i].clear();
others[i].clear();
}
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 4ms
memory: 15236kb
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: 1517ms
memory: 135836kb
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