QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#562776 | #8673. 最短路径 | guosoun | 0 | 5139ms | 175300kb | C++17 | 2.3kb | 2024-09-13 20:44:39 | 2024-09-13 20:44:40 |
Judging History
answer
#include <bits/stdc++.h>
using ll = long long;
const int N = 2e5 + 10;
int main() {
std::cin.tie(0)->sync_with_stdio(0);
int n, m, q;
ll seed;
std::vector<std::vector<std::pair<int, ll>>> g[2];
std::cin >> n >> m >> q >> seed;
g[0].resize(n + 1), g[1].resize(n + 1);
std::mt19937 gen(seed);
unsigned max = -1u / n * n;
auto sample = [&]() {
unsigned x;
do {
x = gen();
} while (x >= max);
return x % n + 1;
};
while (m--) {
int u = sample(), v = sample();
ll w = gen();
if (u == v) continue;
g[0][u].emplace_back(v, w), g[1][v].emplace_back(u, w);
// std::cerr << u << ' ' << v << ' ' << w << '\n';
}
for (int i = 1; i <= n; i++) {
for (int t : {0, 1})
std::sort(g[t][i].begin(), g[t][i].end(),
[&](auto a, auto b) { return a.second < b.second; });
}
static bool vis[2][N];
static ll dis[2][N];
while (q--) {
int s, t;
std::cin >> s >> t;
if (s == t) {
std::cout << 0 << '\n';
continue;
}
memset(dis, 0x3f, sizeof(dis));
memset(vis, 0, sizeof(vis));
std::priority_queue<std::tuple<ll, int, std::vector<std::pair<int, ll>>::iterator>> pq[2];
dis[0][s] = 0, dis[1][t] = 0;
if (g[0][s].size()) pq[0].emplace(g[0][s].begin()->second, s, g[0][s].begin()), vis[0][s] = 1;
if (g[1][t].size()) pq[1].emplace(g[1][t].begin()->second, t, g[1][t].begin()), vis[1][t] = 1;
int x = -1;
for (int c = 0; pq[0].size() && pq[1].size(); c ^= 1) {
auto [d, u, it] = pq[c].top();
auto [v, w] = *it;
pq[c].pop();
if (std::next(it) != g[c][u].end()) pq[c].emplace(dis[c][u] + std::next(it)->second, u, std::next(it));
if (vis[c][v]) continue;
// std::cerr << c << ' ' << v<< ' ' << d << '\n';
dis[c][v] = d, vis[c][v] = 1;
if (vis[c ^ 1][v]) {
x = v;
break;
}
if (g[c][v].size()) pq[c].emplace(d + g[c][v].begin()->second, v, g[c][v].begin());
}
if (x == -1) {
std::cout << -1 << '\n';
continue;
}
ll ans = dis[0][x] + dis[1][x];
for (int u = 1; u <= n; u++)
if (vis[0][u])
for (auto [v, w] : g[0][u])
if (vis[1][v]) ans = std::min(ans, dis[0][u] + w + dis[1][v]);
std::cout << ans << '\n';
}
}
/*
5 10 1 249082683
1 2
*/
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 5
Accepted
time: 2ms
memory: 7060kb
input:
4 8 5 1112792816 2 3 4 3 4 3 3 2 1 4
output:
3419197189 1798364963 1798364963 3986398077 2337967903
result:
ok 5 lines
Test #2:
score: 5
Accepted
time: 248ms
memory: 7332kb
input:
2000 2000 2000 3336994405 659 1650 1678 341 818 235 1380 1865 1927 1366 1233 1673 267 1698 775 1022 1255 1110 1533 1928 1854 169 1579 729 449 1335 943 583 360 50 795 926 1584 911 1924 604 280 309 1429 420 1107 1858 1466 76 265 1109 1077 622 245 1941 957 1434 1560 1128 122 51 229 925 826 1006 851 323...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...
result:
ok 2000 lines
Test #3:
score: 0
Wrong Answer
time: 246ms
memory: 7224kb
input:
1000 2000 2000 1526732796 400 914 837 927 7 271 873 60 934 156 981 329 973 512 276 54 540 278 605 230 681 555 636 706 955 618 640 214 859 696 267 595 38 839 309 12 484 919 746 49 948 337 607 638 438 163 817 869 95 518 534 376 369 331 665 64 736 970 154 41 510 425 876 907 143 803 270 403 350 286 131 ...
output:
59904623239 -1 35500450276 44100407825 123850134981 50939933436 -1 6154157088 -1 57386187180 10597134504 20743442945 41359499813 -1 27245119019 68099995095 -1 -1 51956766819 77195363863 69201551894 63023959449 -1 75200846326 15485138820 -1 5265380455 -1 26369306773 -1 -1 -1 103358899866 24977306827 ...
result:
wrong answer 1st lines differ - expected: '14198403396', found: '59904623239'
Subtask #2:
score: 0
Wrong Answer
Test #6:
score: 0
Wrong Answer
time: 2399ms
memory: 130296kb
input:
3000 3000000 10000 37461678 2873 1368 1757 2000 1262 1822 2484 1778 2055 2096 2545 366 2923 2028 1469 1874 691 631 1173 2967 894 2020 1207 881 373 236 1913 1923 1351 16 1066 2032 471 1561 1047 2043 457 145 2728 1752 2521 1199 1568 904 2515 543 1472 2161 748 2744 748 1908 912 172 2340 2494 977 267 10...
output:
124006081 88671769 166750148 27805775 140740946 74982035 157482381 125994263 103576920 113926616 141610509 119002449 50703016 103341135 164756810 123694963 75066811 198756129 158528990 93034371 138909252 129635229 180208598 182848742 133998654 146576966 164291065 115097665 104827545 105434067 252912...
result:
wrong answer 1st lines differ - expected: '36084543', found: '124006081'
Subtask #3:
score: 0
Wrong Answer
Test #13:
score: 0
Wrong Answer
time: 1285ms
memory: 26520kb
input:
200000 200000 10000 1824322211 104482 112162 130667 13436 36792 142259 51832 97549 15358 180076 128251 92635 45296 195115 62109 38014 22014 86754 79735 103777 94797 96086 196760 5955 45622 59618 12995 62585 55686 156402 23085 68138 170749 148553 97603 160274 112975 22651 116322 190720 84774 57075 23...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...
result:
wrong answer 679th lines differ - expected: '172751101166', found: '278595429405'
Subtask #4:
score: 0
Wrong Answer
Test #17:
score: 0
Wrong Answer
time: 3832ms
memory: 42444kb
input:
200000 500000 10000 3113327438 68816 31422 174349 125983 18111 188786 84806 87249 142007 180723 95611 116398 104758 196349 77547 89859 120350 77199 110906 10209 177461 194861 115505 105566 27493 166237 15676 158290 86204 116010 159979 125659 132461 61989 194289 157721 18830 82910 166696 98162 125208...
output:
318799345651 -1 388484660922 1642164601046 -1 654398237439 -1 -1 1598029899724 1112048403066 -1 -1 522609585381 549083937601 1146065708873 -1 -1 -1 212236159646 880886090002 1436215921900 830939416944 -1 636629719537 1665344012955 547324399452 -1 1008869361349 315279636469 -1 640626466690 7245817163...
result:
wrong answer 1st lines differ - expected: '21671419385', found: '318799345651'
Subtask #5:
score: 0
Wrong Answer
Test #21:
score: 0
Wrong Answer
time: 3549ms
memory: 42176kb
input:
200000 500000 10000 1843053063 3409 108359 168924 184622 13119 119837 109492 38050 97152 51201 49047 12472 183998 191613 193074 177289 194248 104409 15509 88499 61967 143398 4532 56790 196650 158711 63655 70744 140178 107299 63530 87330 127334 159237 7134 184418 125289 28604 176966 179527 181695 128...
output:
611326275577 179351859890 370142225993 649231266562 -1 365807638986 1123033762416 362094808599 464411753222 417543876210 373739998636 818444060751 1076487902945 891699323994 599896729479 707649956125 531439131777 -1 -1 1089058106838 1186878499759 980389100283 199119219279 182343302818 519529819523 4...
result:
wrong answer 1st lines differ - expected: '18098332289', found: '611326275577'
Subtask #6:
score: 0
Wrong Answer
Test #24:
score: 0
Wrong Answer
time: 3554ms
memory: 168384kb
input:
100000 3000000 10000 3892765041 14843 34156 43390 49542 38564 95501 26194 87126 18638 53346 69414 47011 95472 58303 44370 77172 75652 90555 94386 31888 47911 9905 70599 97061 52764 24896 31445 15589 82314 43852 97155 93412 11834 45082 75614 42459 67802 32024 82389 4968 32860 62514 97630 28012 14839 ...
output:
19352439034 18667511741 17946368475 22649684614 42921007684 22780236477 5835727247 21800002900 23641020961 4247923828 15116434401 25381803778 12318196683 21216646432 19269274443 16023861000 40359696346 14381881132 18242150859 10783004161 14366802091 12514370506 21685735080 18889129728 10100843845 18...
result:
wrong answer 1st lines differ - expected: '1547972368', found: '19352439034'
Subtask #7:
score: 0
Wrong Answer
Test #33:
score: 0
Wrong Answer
time: 5139ms
memory: 175300kb
input:
200000 3000000 10000 3910662331 161257 40967 50546 86049 199665 199302 177403 36274 158790 143151 193304 78511 28032 149723 96394 37099 2157 76024 195400 34830 41933 147591 191613 96468 194837 67293 57992 63117 24749 6694 117818 87323 46130 53470 174812 24950 149173 124886 119910 54123 2297 124533 5...
output:
43579730145 80119113502 67951540108 68335515046 69793819577 40931740543 40654273185 23029266674 59421813955 74353758169 42352064706 70148177540 18267311855 28238630546 73190105604 91030504317 46999439115 98655575637 104148087584 27831435107 59328037376 49238586773 20527892357 83819031391 43554135472...
result:
wrong answer 1st lines differ - expected: '3371897180', found: '43579730145'