QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#420092 | #8673. 最短路径 | cmk666 | 10 | 4852ms | 385596kb | C++23 | 9.8kb | 2024-05-24 14:36:23 | 2024-05-24 14:36:24 |
Judging History
answer
/* _ _ _ _ __ __ __
/ \ _ _ | |_ | |__ ___ _ __ _ ___ _ __ ___ | | __ / /_ / /_ / /_
/ _ \ | | | | | __| | '_ \ / _ \ | '__| (_) / __| | '_ ` _ \ | |/ / | '_ \ | '_ \ | '_ \
/ ___ \ | |_| | | |_ | | | | | (_) | | | _ | (__ | | | | | | | < | (_) | | (_) | | (_) |
/_/ \_\ \__,_| \__| |_| |_| \___/ |_| (_) \___| |_| |_| |_| |_|\_\ \___/ \___/ \___/
[Created Time: 2024-05-24 13:58:24]
[Last Modified Time: 2024-05-24 14:36:05] */
#pragma GCC optimize("Ofast", "unroll-loops")
#include<bits/stdc++.h>
#ifdef LOCAL
#include"debug.h"
#else
#define D(...) ((void)0)
#endif
using namespace std; using ll = long long;
#define For(i, j, k) for ( int i = (j) ; i <= (k) ; i++ )
#define Fol(i, j, k) for ( int i = (j) ; i >= (k) ; i-- )
namespace FastIO
{
// ------------------------------
// #define DISABLE_MMAP
// ------------------------------
#if ( defined(LOCAL) || defined(_WIN32) ) && !defined(DISABLE_MMAP)
#define DISABLE_MMAP
#endif
#ifdef LOCAL
inline char gc() { return getchar(); }
inline void pc(char c) { putchar(c); }
#else
#ifdef DISABLE_MMAP
inline constexpr int _READ_SIZE = 1 << 18;
inline static char _read_buffer[_READ_SIZE], *_read_ptr = nullptr, *_read_ptr_end = nullptr;
inline char gc()
{
if ( __builtin_expect(_read_ptr == _read_ptr_end, false) )
{
_read_ptr = _read_buffer, _read_ptr_end = _read_buffer + fread(_read_buffer, 1, _READ_SIZE, stdin);
if ( __builtin_expect(_read_ptr == _read_ptr_end, false) ) return EOF;
}
return *_read_ptr++;
}
#else
#include<sys/mman.h>
inline static const char *_read_ptr = (const char *)mmap(nullptr, 0x7fffffff, 1, 2, 0, 0);
inline char gc() { return *_read_ptr++; }
#endif
inline constexpr int _WRITE_SIZE = 1 << 18;
inline static char _write_buffer[_WRITE_SIZE], *_write_ptr = _write_buffer;
inline void pc(char c)
{
*_write_ptr++ = c;
if ( __builtin_expect(_write_buffer + _WRITE_SIZE == _write_ptr, false) )
fwrite(_write_buffer, 1, _write_ptr - _write_buffer, stdout), _write_ptr = _write_buffer;
}
inline struct _auto_flush
{
inline ~_auto_flush() { fwrite(_write_buffer, 1, _write_ptr - _write_buffer, stdout); }
} _auto_flush;
#endif
template < class T > inline constexpr bool _is_signed = numeric_limits < T >::is_signed;
template < class T > inline constexpr bool _is_unsigned = numeric_limits < T >::is_integer && !_is_signed < T >;
#if __SIZEOF_LONG__ == 64
template <> inline constexpr bool _is_signed < __int128 > = true;
template <> inline constexpr bool _is_unsigned < __uint128_t > = true;
#endif
inline void read(char &c) { do c = gc(); while ( !isgraph(c) ); }
inline void read_cstr(char *s)
{
char c = gc(); while ( !isgraph(c) ) c = gc();
while ( isgraph(c) ) *s++ = c, c = gc(); *s = 0;
}
inline void read(string &s)
{
char c = gc(); s.clear(); while ( !isgraph(c) ) c = gc();
while ( isgraph(c) ) s.push_back(c), c = gc();
}
template < class T, enable_if_t < _is_signed < T >, int > = 0 >
inline void read(T &x)
{
char c = gc(); bool f = true; x = 0;
while ( !isdigit(c) ) { if ( c == 45 ) f = false; c = gc(); }
if ( f ) while ( isdigit(c) ) x = x * 10 + ( c & 15 ), c = gc();
else while ( isdigit(c) ) x = x * 10 - ( c & 15 ), c = gc();
}
template < class T, enable_if_t < _is_unsigned < T >, int > = 0 >
inline void read(T &x)
{
char c = gc(); while ( !isdigit(c) ) c = gc();
x = 0; while ( isdigit(c) ) x = x * 10 + ( c & 15 ), c = gc();
}
inline void write(char c) { pc(c); }
inline void write_cstr(const char *s) { while ( *s ) pc(*s++); }
inline void write(const string &s) { for ( char c : s ) pc(c); }
template < class T, enable_if_t < _is_signed < T >, int > = 0 >
inline void write(T x)
{
char buffer[numeric_limits < T >::digits10 + 1]; int digits = 0;
if ( x >= 0 ) do buffer[digits++] = ( x % 10 ) | 48, x /= 10; while ( x );
else { pc(45); do buffer[digits++] = -( x % 10 ) | 48, x /= 10; while ( x ); }
while ( digits ) pc(buffer[--digits]);
}
template < class T, enable_if_t < _is_unsigned < T >, int > = 0 >
inline void write(T x)
{
char buffer[numeric_limits < T >::digits10]; int digits = 0;
do buffer[digits++] = ( x % 10 ) | 48, x /= 10; while ( x );
while ( digits ) pc(buffer[--digits]);
}
template < int N > struct _tuple_io_helper
{
template < class ...T > static inline void _read(tuple < T... > &x) { _tuple_io_helper < N - 1 >::_read(x), read(get<N - 1>(x)); }
template < class ...T > static inline void _write(const tuple < T... > &x) { _tuple_io_helper < N - 1 >::_write(x), pc(32), write(get<N - 1>(x)); }
};
template <> struct _tuple_io_helper < 1 >
{
template < class ...T > static inline void _read(tuple < T... > &x) { read(get<0>(x)); }
template < class ...T > static inline void _write(const tuple < T... > &x) { write(get<0>(x)); }
};
template < class ...T > inline void read(tuple < T... > &x) { _tuple_io_helper < sizeof...(T) >::_read(x); }
template < class ...T > inline void write(const tuple < T... > &x) { _tuple_io_helper < sizeof...(T) >::_write(x); }
template < class T1, class T2 > inline void read(pair < T1, T2 > &x) { read(x.first), read(x.second); }
template < class T1, class T2 > inline void write(const pair < T1, T2 > &x) { write(x.first), pc(32), write(x.second); }
template < class T1, class ...T2 > inline void read(T1 &x, T2 &...y) { read(x), read(y...); }
template < class ...T > inline void read_cstr(char *x, T *...y) { read_cstr(x), read_cstr(y...); }
template < class T1, class ...T2 > inline void write(const T1 &x, const T2 &...y) { write(x), write(y...); }
template < class ...T > inline void write_cstr(const char *x, const T *...y) { write_cstr(x), write_cstr(y...); }
template < class T > inline void print(const T &x) { write(x); }
inline void print_cstr(const char *x) { write_cstr(x); }
template < class T1, class ...T2 > inline void print(const T1 &x, const T2 &...y) { write(x), pc(32), print(y...); }
template < class ...T > inline void print_cstr(const char *x, const T *...y) { write_cstr(x), pc(32), print_cstr(y...); }
inline void println() { pc(10); } inline void println_cstr() { pc(10); }
template < class ...T > inline void println(const T &...x) { print(x...), pc(10); }
template < class ...T > inline void println_cstr(const T *...x) { print_cstr(x...), pc(10); }
} using FastIO::read, FastIO::read_cstr, FastIO::write, FastIO::write_cstr, FastIO::println, FastIO::println_cstr;
template <class T, int N, int M> struct darry_with_radix_sort {
struct E {int idx; T val;} e[M], f[M];
T a[M];
int b[N], c[2 << (std::__lg(N) / 2)], n, m, o;
struct V {
T *b, *e;
V(T *b_, T *e_) : b(b_), e(e_) {}
T* begin() const { return b; }
T* end() const { return e; }
T operator[](std::size_t i) const { return *(b + i); }
std::size_t size() const { return e - b; }
};
void init(int n_) { n = n_, m = 0, o = std::__lg(n) / 2 + 1, std::fill(b + 1, b + n + 1, 0); }
template <class ...U>
void emplace(int idx, U&&... val) {
b[idx]++, e[++m].idx = idx, std::construct_at(&e[m].val, val...);
}
void build() {
std::fill(c, c + (1 << o), 0);
for (int i = 1; i <= m; i++) c[e[i].idx & ((1 << o) - 1)]++;
for (int i = 1; i < (1 << o); i++) c[i] += c[i - 1];
for (int i = 1; i <= m; i++) f[c[e[i].idx & ((1 << o) - 1)]--] = std::move(e[i]);
std::fill(c, c + (1 << o), 0);
for (int i = 1; i <= m; i++) c[f[i].idx >> o]++;
for (int i = 1; i < (1 << o); i++) c[i] += c[i - 1];
for (int i = m; i; i--) a[c[f[i].idx >> o]--] = std::move(f[i].val);
b[0] = 1;
for (int i = 1; i <= n; i++) b[i] += b[i - 1];
}
V operator[](int idx) { return V(a + b[idx - 1], a + b[idx]); }
};
constexpr ll inf = numeric_limits < ll >::max() >> 1;
int n, m, q, o, u, v, s[2], id[2][200009]; ll w, d[2][200009], lim, ans; bool used[2][200009];
darry_with_radix_sort < pair < int, ll >, 200009, 3000009 > g[2]; vector < int > nd[2];
#include<ext/pb_ds/priority_queue.hpp>
__gnu_pbds::priority_queue < tuple < ll, int, int >, greater < tuple < ll, int, int > >,
__gnu_pbds::pairing_heap_tag > pq[2];
inline void ext(int o, int u)
{
while ( id[o][u] < (int)g[o][u].size() )
{
auto [v, w] = g[o][u][id[o][u]++];
if ( d[o][v] > d[o][u] + w ) { pq[o].push(tuple(d[o][v] = d[o][u] + w, v, u)); return; }
}
}
inline void work()
{
For(o, 0, 1)
{
for ( int i : nd[o] ) used[o][i] = false, d[o][i] = inf, id[o][i] = 0;
read(u), nd[o].clear(), pq[o].clear(), pq[o].push(tuple(d[o][u] = 0, u, 0));
}
for ( int o = v = 0 ; pq[0].size() || pq[1].size() ; o = !o ) if ( pq[o].size() )
{
auto [_, u, fr] = pq[o].top(); pq[o].pop();
if ( used[o][u] ) continue; used[o][u] = true, nd[o].push_back(u);
if ( used[!o][u] ) { v = u; break; }
ext(o, u); if ( fr ) ext(o, fr);
}
if ( !v ) { println(-1); return; }
ans = d[0][v] + d[1][v];
For(o, 0, 1) for ( int i : nd[o] )
{
lim = ( d[o][v] - d[o][i] ) << 1;
for ( auto [v, w] : g[o][i] )
{
if ( w > lim ) break;
if ( used[!o][v] ) ans = min(ans, d[o][i] + d[!o][v] + w);
}
}
println(ans);
}
int main()
{
read(n, m, q);
For(o, 0, 1) g[o].init(n);
{
unsigned mx = -1u / n * n, s; read(s); mt19937 rnd(s);
const auto gen = [&] { unsigned x; do x = rnd(); while ( x >= mx ); return x % n + 1; };
For(i, 1, m) u = gen(), v = gen(), w = rnd(), g[0].emplace(u, v, w), g[1].emplace(v, u, w);
}
For(o, 0, 1)
{
g[o].build(), nd[o].reserve(n), fill(d[o] + 1, d[o] + n + 1, inf);
For(i, 1, n) sort(g[o][i].begin(), g[o][i].end(), [&](auto x, auto y) { return x.second < y.second; });
}
while ( q-- ) work();
return 0;
}
// 想上GM捏 想上GM捏 想上GM捏 想上GM捏 想上GM捏
// 伊娜可爱捏 伊娜贴贴捏
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 5
Accepted
time: 11ms
memory: 378684kb
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
Wrong Answer
time: 36ms
memory: 378852kb
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:
wrong answer 1922nd lines differ - expected: '29199491404', found: '31116566742'
Subtask #2:
score: 0
Wrong Answer
Test #6:
score: 0
Wrong Answer
time: 558ms
memory: 379048kb
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:
36084543 49860181 45803385 27805775 41392651 43506617 39517515 39687913 37675345 23367579 37276839 32364058 50703016 26615083 25983590 59037405 42921191 31222991 39092809 25257238 36267824 62523556 34199475 45804995 36929459 34257048 43789135 55135658 31005342 41408425 35033769 37667712 42873640 378...
result:
wrong answer 16th lines differ - expected: '51209814', found: '59037405'
Subtask #3:
score: 10
Accepted
Test #13:
score: 10
Accepted
time: 424ms
memory: 385444kb
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:
ok 10000 lines
Test #14:
score: 0
Accepted
time: 40ms
memory: 385512kb
input:
200000 100000 10000 1394653802 99794 128174 196511 141958 176353 6707 19037 95308 12331 132159 47825 12373 47277 130874 165656 114428 81800 12371 165878 128160 33280 71225 139344 138789 126396 182051 103407 151857 20873 18698 155652 38063 150807 191146 57310 174863 114490 88197 158133 29636 137962 1...
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 10000 lines
Test #15:
score: 0
Accepted
time: 79ms
memory: 382568kb
input:
100000 100000 10000 913053279 28316 35031 36768 9164 74111 12192 71120 23394 97477 34141 50880 24433 99500 23365 99785 571 95784 50853 8313 70744 33410 27807 29073 96498 82964 79943 32999 84423 90798 98756 98245 89258 89589 49557 90152 40866 53406 41385 33889 39018 42199 52421 13784 26639 85311 5769...
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 10000 lines
Test #16:
score: 0
Accepted
time: 23ms
memory: 379504kb
input:
1 1 10000 1920830832 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 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...
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:
ok 10000 lines
Subtask #4:
score: 0
Time Limit Exceeded
Test #17:
score: 0
Time Limit Exceeded
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:
result:
Subtask #5:
score: 0
Time Limit Exceeded
Test #21:
score: 0
Time Limit Exceeded
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:
result:
Subtask #6:
score: 0
Wrong Answer
Test #24:
score: 0
Wrong Answer
time: 3003ms
memory: 382632kb
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:
1547972368 1533240012 1192488694 1802115335 1491444021 1888896300 1720188008 1762089620 1815841406 1831208977 1250925907 1756812381 2027344758 1385409721 2044038817 1877583272 1632784703 2090242303 1694524102 1818975564 1429598050 1599437722 2286394605 1416358110 1929044811 2022891575 1487757623 156...
result:
wrong answer 15th lines differ - expected: '1937527554', found: '2044038817'
Subtask #7:
score: 0
Wrong Answer
Test #33:
score: 0
Wrong Answer
time: 4852ms
memory: 385596kb
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:
3371897180 3059012504 3899803743 4918664465 3834117056 3101758258 4211432244 3700678845 3320322266 4020388668 3314213999 4156507838 3045843635 3379778417 3201003504 4511026914 4847106102 3502897631 3579081638 3470448652 4322207527 2160161436 4372954162 3841655899 3367608876 3864513044 4225021719 377...
result:
wrong answer 51st lines differ - expected: '4917617697', found: '5238567595'