QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#430840 | #2976. 旅行者 | xhgua | 100 ✓ | 3300ms | 18216kb | C++14 | 2.0kb | 2024-06-04 15:50:35 | 2024-06-04 15:50:35 |
Judging History
answer
#include <bits/stdc++.h>
using i64 = long long;
constexpr int N = 1e5 + 5, M = 5e5 + 5;
constexpr i64 INF = (1ll << 60);
int T, n, m, k;
int a[N];
i64 dis[N];
bool vis[N];
std::vector<std::pair<int, int>> G[N];
struct Edge { int u, v, w; } E[M];
void dijkstra(int s) {
for (int i = 0; i <= n + 1; i++) dis[i] = INF, vis[i] = false;
dis[s] = 0;
std::priority_queue<std::pair<int, int>> q;
q.push({0, s});
while (!q.empty()) {
int u = q.top().second; q.pop();
if (vis[u]) continue;
vis[u] = true;
for (auto e : G[u]) {
int v = e.first, w = e.second;
if (dis[u] + w < dis[v]) {
dis[v] = dis[u] + w;
q.push({-dis[v], v});
}
}
}
}
void solve() {
std::cin >> n >> m >> k;
for (int i = 1; i <= m; i++) std::cin >> E[i].u >> E[i].v >> E[i].w;
for (int i = 1; i <= k; i++) std::cin >> a[i];
i64 ans = INF;
for (int i = std::__lg(n); ~i; i--) {
for (int j = 0; j <= n + 1; j++) G[j].clear();
for (int j = 1; j <= m; j++) {
int u = E[j].u, v = E[j].v, w = E[j].w;
G[u].push_back({v, w});
}
for (int j = 1; j <= k; j++) {
if (a[j] >> i & 1) G[0].push_back({a[j], 0});
else G[a[j]].push_back({n + 1, 0});
}
dijkstra(0); ans = std::min(ans, dis[n + 1]);
for (int j = 0; j <= n + 1; j++) G[j].clear();
for (int j = 1; j <= m; j++) {
int u = E[j].u, v = E[j].v, w = E[j].w;
G[u].push_back({v, w});
}
for (int j = 1; j <= k; j++) {
if (a[j] >> i & 1) G[a[j]].push_back({n + 1, 0});
else G[0].push_back({a[j], 0});
}
dijkstra(0); ans = std::min(ans, dis[n + 1]);
}
std::cout << ans << "\n";
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cin >> T;
while (T--) solve();
return 0;
}
詳細信息
Test #1:
score: 10
Accepted
time: 14ms
memory: 6112kb
input:
5 1000 3000 10 389 68 716480 563 888 725160 476 558 190526 111 513 829362 5 11 132253 151 121 292979 521 687 912780 520 851 287998 559 437 689929 461 558 597352 426 591 516402 89 191 225976 561 226 796204 33 61 243259 603 245 788196 691 963 564200 239 329 900548 441 9 482235 797 494 489734 901 865 4...
output:
758454 418889 226460 514216 281642
result:
ok 5 lines
Test #2:
score: 10
Accepted
time: 13ms
memory: 8124kb
input:
5 1000 4000 20 853 484 47824 141 129 564076 805 881 707630 72 314 992304 265 153 752230 864 851 456185 5 13 807425 326 711 664266 623 281 330013 986 145 538365 477 912 766900 75 929 973226 731 383 170315 451 641 404266 774 537 66373 250 201 3920 291 30 176413 613 817 985960 89 940 90196 876 892 3553...
output:
36850 194100 60250 27490 105508
result:
ok 5 lines
Test #3:
score: 10
Accepted
time: 437ms
memory: 15604kb
input:
5 100000 150000 100 43479 11015 239064 98702 36396 1516503 57076 9016 801856 10150 92 1582364 65966 10218 442211 85729 64257 481101 96706 40563 1832790 81321 36709 332310 47746 22075 2161139 35868 20570 168792 14392 2521 742683 27125 6023 616531 16294 1589 1813362 58971 51151 1970060 54535 7174 1254...
output:
3035011 3552205 1837280 2035777 891748
result:
ok 5 lines
Test #4:
score: 10
Accepted
time: 468ms
memory: 15392kb
input:
5 100000 150000 250 69372 8290 2015140 31837 2054 1016052 7042 4708 1025637 98597 25907 563113 77701 12821 156572 12351 12296 474579 34341 8961 1733464 69995 68696 1429546 70197 35225 1736911 73591 69397 2085683 45917 27340 1002904 7074 4901 289489 31816 20827 1475109 26233 23719 527675 57593 29085 ...
output:
783071 886098 3007427 1816531 2405595
result:
ok 5 lines
Test #5:
score: 10
Accepted
time: 2501ms
memory: 15092kb
input:
5 90000 200000 1000 1 2 3188 2 3 4040 3 4 8410 4 5 8960 5 6 448 6 7 6641 7 8 4240 8 9 9478 9 10 0 10 11 966 11 12 5680 12 13 5835 13 14 9256 14 15 8328 15 16 156 16 17 872 17 18 4500 18 19 5624 19 20 3552 20 21 7940 21 22 2704 22 23 4022 23 24 4511 24 25 5556 25 26 4337 26 27 648 27 28 7379 28 29 76...
output:
163271 157394 148844 144672 153887
result:
ok 5 lines
Test #6:
score: 10
Accepted
time: 3300ms
memory: 15796kb
input:
5 95000 200000 800 1 2 1180 2 3 3154 3 4 1480 4 5 4429 5 6 9205 6 7 6308 7 8 8902 8 9 5622 9 10 9430 10 11 1064 11 12 4202 12 13 3940 13 14 4640 14 15 2704 15 16 8280 16 17 1108 17 18 2532 18 19 7466 19 20 8600 20 21 5440 21 22 3985 22 23 572 23 24 3392 24 25 9258 25 26 4768 26 27 2646 27 28 9789 28...
output:
346929 342089 301744 332090 367272
result:
ok 5 lines
Test #7:
score: 10
Accepted
time: 3062ms
memory: 17236kb
input:
5 90000 190000 800 1 2 3326 2 3 1846 3 4 8968 4 5 5860 5 6 6625 6 7 7228 7 8 4920 8 9 4960 9 10 4598 10 11 8466 11 12 9190 12 13 5458 13 14 7500 14 15 246 15 16 487 16 17 8928 17 18 9945 18 19 4848 19 20 7714 20 21 3085 21 22 4536 22 23 4150 23 24 3680 24 25 3680 25 26 3893 26 27 3761 27 28 3945 28 ...
output:
464109 442389 450149 439500 441239
result:
ok 5 lines
Test #8:
score: 10
Accepted
time: 2001ms
memory: 18216kb
input:
3 95456 333926 50 91739 50130 1928 2581 67375 1826 10250 88437 1064 22492 30899 1760 13354 37007 1525 12582 68875 1702 91441 4062 1384 24272 47628 1136 86580 76398 1847 73206 89103 1496 67249 18700 1104 5609 65504 1350 14671 24818 1432 70400 49948 1860 70361 19878 1528 22642 65122 1858 12127 32740 1...
output:
2812 3772 7506
result:
ok 3 lines
Test #9:
score: 10
Accepted
time: 1017ms
memory: 16836kb
input:
3 100000 200000 20 20385 47241 9003 50705 61167 10952 87429 35569 9986 2773 46145 9312 5505 47853 6803 83967 36378 5656 73777 92072 1960 80353 94349 6112 20393 86047 1545 1946 58065 9939 21751 2017 3906 90865 73475 3278 13670 21301 5316 16535 76982 9565 55955 12350 6804 36298 98977 5162 42151 60701 ...
output:
13952 13955 1492
result:
ok 3 lines
Test #10:
score: 10
Accepted
time: 1049ms
memory: 11800kb
input:
4 100000 100999 10 3161 61826 88091 53085 89563 63500 24259 66347 84908 36584 43955 55108 54536 50606 21000 53878 18996 2122 85017 66884 1471 11526 98922 66810 42543 40832 46440 93302 39784 1938 5256 56831 94328 68811 54799 7756 58429 63416 20189 95999 8467 63353 6103 16838 63455 737 19278 81586 707...
output:
1571200 32402748 19535837 14056
result:
ok 4 lines