QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#562765 | #8673. 最短路径 | guosoun | 0 | 3456ms | 171388kb | C++17 | 2.3kb | 2024-09-13 20:41:07 | 2024-09-13 20:41:07 |
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, 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];
int x = -1;
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;
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';
}
}
/*
4 8 1 1112792816
2 3
*/
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 5
Accepted
time: 0ms
memory: 7120kb
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: 0
Wrong Answer
time: 1ms
memory: 4028kb
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:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
wrong answer 1st lines differ - expected: '-1', found: '0'
Subtask #2:
score: 0
Wrong Answer
Test #6:
score: 0
Wrong Answer
time: 2283ms
memory: 130268kb
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: 2227ms
memory: 26612kb
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: 104ms
memory: 38596kb
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:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
wrong answer 1st lines differ - expected: '21671419385', found: '0'
Subtask #5:
score: 0
Wrong Answer
Test #21:
score: 0
Wrong Answer
time: 3456ms
memory: 42164kb
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 9114861777597660798 365807638986 1123033762416 362094808599 464411753222 417543876210 373739998636 818444060751 1076487902945 891699323994 599896729479 707649956125 531439131777 9114861777597660798 9114861777597660798 1089058106838 1186878499759 98...
result:
wrong answer 1st lines differ - expected: '18098332289', found: '611326275577'
Subtask #6:
score: 0
Wrong Answer
Test #24:
score: 0
Wrong Answer
time: 433ms
memory: 164608kb
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:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
wrong answer 1st lines differ - expected: '1547972368', found: '0'
Subtask #7:
score: 0
Wrong Answer
Test #33:
score: 0
Wrong Answer
time: 522ms
memory: 171388kb
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:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
wrong answer 1st lines differ - expected: '3371897180', found: '0'