QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#916109 | #603. 单源最短路径 | Floze3 | 100 ✓ | 1ms | 3968kb | C++20 | 7.1kb | 2025-02-26 19:28:33 | 2025-02-26 19:28:33 |
Judging History
answer
#include <bits/stdc++.h>
#ifndef ONLINE_JUDGE
#ifdef CPH
#include "/home/floze3/OI/debug.hpp"
#else
#include "/home/floze3/OI/debug_colored.hpp"
#endif
#else
#define debug(...) 42
#define debugArr(...) 42
#define look_time 42
#define look_memory 42
#endif
#define mp(x, y) std::make_pair(x, y)
#define mt std::make_tuple
#define eb emplace_back
#define fi first
#define se second
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define file(name) \
freopen(name ".in", "r", stdin); \
freopen(name ".out", "w", stdout);
#define fs(x) std::fixed << std::setprecision(x)
#define il inline
#define Avada_Kedavra return 0
#define _IOS \
std::ios::sync_with_stdio(false); \
std::cin.tie(nullptr), std::cout.tie(nullptr)
#define RANDOM_SEED std::chrono::steady_clock::now().time_since_epoch().count()
#define multitask \
int _; rd >> _; \
while (_--)
using std::cerr;
namespace TYPEDEF {
using i32 = int32_t;
using i64 = long long;
using u64 = unsigned long long;
using u32 = uint32_t;
using i128 = __int128_t;
using u128 = __uint128_t;
using pii = std::pair<i32, i32>;
using pi64 = std::pair<i64, i64>;
using vi = std::vector<i32>;
using vu = std::vector<u32>;
using vi64 = std::vector<i64>;
using vu64 = std::vector<u64>;
using vpii = std::vector<pii>;
using vpi64 = std::vector<pi64>;
using si = std::stack<i32>;
using si64 = std::stack<i64>;
using su64 = std::stack<u64>;
using spii = std::stack<pii>;
using spi64 = std::stack<pi64>;
using qi = std::queue<i32>;
using qi64 = std::queue<i64>;
using qu64 = std::queue<u64>;
using qpii = std::queue<pii>;
using qpi64 = std::queue<pi64>;
using siset = std::set<i32>;
using si64set = std::set<i64>;
using su64set = std::set<u64>;
using spiiset = std::set<pii>;
using spi64set = std::set<pi64>;
using str = std::string;
using vstr = std::vector<str>;
using f64 = long double;
template <typename T> using vc = std::vector<T>;
template <typename FI, typename SE> using pr = std::pair<FI, SE>;
} // namespaec TYPEDEF
using namespace TYPEDEF;
struct Scanner {
FILE* stream;
Scanner(FILE* s): stream(s) {}
char buf[1 << 20], *l = buf, *r = buf;
bool flush() { l = buf; r = l + fread(buf, 1, 1 << 20, stream); return l == r; }
void get(char &c) {
#ifndef ONLINE_JUDGE
c = getchar();
#else
c = l == r && flush() ? ' ' : *l++;
#endif
}
friend Scanner &operator>>(Scanner &in, char &c) { return in.get(c), in; }
friend Scanner &operator>>(Scanner &in, char* s) {
for (in.get(s[0]); isspace(s[0]); in.get(s[0]));
for (i32 i = 0; !isspace(s[i]) || (s[i] = '\0'); i++) in.get(s[i + 1]);
return in;
}
friend Scanner &operator>>(Scanner &in, str &s) {
char c;
for (in.get(c); isspace(c); in.get(c));
for (s = ""; !isspace(c); in.get(c)) s += c;
return in;
}
friend Scanner &operator>>(Scanner &in, i128 &x) {
char c, f = '+';
for (in.get(c); !isdigit(c); in.get(c))
if (c == '-') f = c;
for (x = 0; isdigit(c); in.get(c)) x = (x << 1) + (x << 3) + c - '0';
if (f == '-') x = -x;
return in;
}
template <class T> requires std::is_integral_v<T>
friend Scanner &operator>>(Scanner &in, T &x) {
char c, f = '+';
for (in.get(c); !isdigit(c); in.get(c))
if constexpr (std::is_signed_v<T>) f = c;
for (x = 0; isdigit(c); in.get(c)) x = x * 10 + c - '0';
if constexpr (std::is_signed_v<T>) x = f == '-' ? -x : x;
return in;
}
template <class T> requires std::is_floating_point_v<T>
friend Scanner &operator>>(Scanner &in, T &x) {
std::string s; in >> s; x = std::stod(s);
return in;
}
};
struct Printer {
FILE* stream;
Printer(FILE* s): stream(s) {}
char buf[1 << 20], *l = buf, *r = buf + (1 << 20) - 1;
int format = 0, precision = 15;
~Printer() { flush(); }
void flush() { fwrite(buf, 1, l - buf, stream); l = buf; }
void put(const char &c) {
#ifndef ONLINE_JUDGE
putchar(c);
#else
*l++ = c;
if (l == r) flush();
#endif
}
friend Printer &operator<<(Printer &out, const char &c) {
return out.put(c), out;
}
friend Printer &operator<<(Printer &out, const char* s) {
for (int i = 0; s[i] != '\0'; i++) out.put(s[i]);
return out;
}
friend Printer &operator<<(Printer &out, char* s) {
for (int i = 0; s[i] != '\0'; i++) out.put(s[i]);
return out;
}
friend Printer &operator<<(Printer &out, const str &s) {
for (int i = 0, n = s.size(); i < n; i++) out.put(s[i]);
return out;
}
friend Printer &operator<<(Printer &out, i128 x) {
static short s[40], top = 0;
if (x < 0) out.put('-'), x = -x;
do s[++top] = x % 10, x /= 10; while (x);
while (top) out.put(s[top--] + '0');
return out;
}
template <typename T> requires std::is_integral_v<T>
friend Printer& operator <<(Printer &out, T x) {
static short s[40];
static i32 i = 0;
if (x == 0) { out.put('0'); return out; }
if constexpr (std::is_signed_v<T>) x = x < 0 ? out.put('-'), -x : x;
while (x > 0) s[++i] = x % 10 + '0', x /= 10;
while (i > 0) out.put(s[i--]);
return out;
}
template <typename T> requires std::is_floating_point_v<T>
friend Printer& operator <<(Printer &out, T x) {
std::ostringstream oss;
oss << std::fixed << std::setprecision(out.precision) << x;
return out << oss.str();
}
};
Scanner rd(stdin);
Printer wt(stdout);
/*===============================ALGOS===============================*/
namespace basic_algorithm {
template <typename T> il T abs(T a) { return a >= 0 ? a : -a; }
template <typename T> il void chmin(T &a, T b) { if (a > b) a = b; }
template <typename T> il void chmax(T &a, T b) { if (a < b) a = b; }
template <typename T> il T lowbit(T x) { return (x & (-x)); }
il i32 pct(i32 x) { return __builtin_popcount(x); }
il i32 pct(u32 x) { return __builtin_popcount(x); }
il i32 pct(i64 x) { return __builtin_popcountll(x); }
il i32 pct(u64 x) { return __builtin_popcountll(x); }
} // namespace basic_algorithm
using namespace basic_algorithm;
/*================================END================================*/
constexpr i32 N = 2505;
// constexpr i32 M = 6205;
constexpr i32 mod = 1e9 + 7;
constexpr i32 inf = 0x3f3f3f3f;
constexpr i64 inf64 = 0x3f3f3f3f3f3f3f3fll;
// constexpr f64 pi = std::numbers::pi_v<f64>;
// std::mt19937 rng(RANDOM_SEED);
bool mst;
i32 n, m, s, t;
i64 dis[N];
bool vis[N];
vpii g[N];
std::priority_queue<pr<i64, i32>, vc<pr<i64, i32> >, std::greater<> > q;
bool med;
signed main() {
rd >> n >> m >> s >> t;
for (i32 i = 1, u, v, w; i <= m; ++i) {
rd >> u >> v >> w;
g[u].eb(v, w), g[v].eb(u, w);
}
memset(dis, 0x3f, sizeof(dis)), dis[s] = 0;
q.push(mp(0, s));
while (!q.empty()) {
auto [_, u] = q.top(); q.pop();
if (vis[u]) continue;
vis[u] = true;
for (auto [v, w] : g[u]) {
if (dis[v] > dis[u] + w) {
dis[v] = dis[u] + w;
q.push(mp(dis[v], v));
}
}
}
wt << dis[t];
Avada_Kedavra;
}
/*
all the things you do
the words you say
it all comes back to you
*/
Details
Tip: Click on the bar to expand more detailed information
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 0ms
memory: 3584kb
input:
7 11 5 4 2 4 2 1 4 3 7 2 2 3 4 3 5 7 5 7 3 3 6 1 1 6 3 4 2 4 3 5 6 3 7 2 1
output:
7
result:
ok 1 number(s): "7"
Test #2:
score: 10
Accepted
time: 0ms
memory: 3584kb
input:
10 20 9 4 5 6 308 8 10 696 4 2 569 8 6 471 1 2 874 5 3 130 4 5 804 8 9 89 10 4 717 10 9 41 7 6 998 1 6 639 7 9 650 7 8 339 3 1 597 9 1 622 7 10 2 5 1 4 1 4 372 1 10 163
output:
576
result:
ok 1 number(s): "576"
Test #3:
score: 10
Accepted
time: 0ms
memory: 3584kb
input:
20 43 11 19 8 14 569 17 13 859 11 14 571 18 14 583 14 5 569 9 1 342 14 6 397 14 17 640 12 1 331 19 12 999 16 1 203 19 6 493 9 14 645 7 4 118 15 6 218 15 20 164 13 16 737 1 15 548 1 17 478 4 15 286 4 17 964 12 14 165 15 7 759 1 5 976 19 11 491 15 11 286 14 1 889 10 17 852 15 16 6 20 3 563 12 7 538 11...
output:
491
result:
ok 1 number(s): "491"
Test #4:
score: 10
Accepted
time: 1ms
memory: 3584kb
input:
50 122 14 3 49 4 977 17 16 209 10 8 573 14 45 989 41 49 988 11 13 548 34 46 367 29 35 30 13 16 220 50 11 280 42 16 608 46 48 423 48 9 381 27 13 514 26 2 725 38 1 10 33 18 688 19 47 750 36 18 650 49 47 393 14 6 688 13 29 387 22 11 10 45 37 974 9 12 926 35 49 776 44 33 993 34 1 592 33 39 409 34 37 858...
output:
1215
result:
ok 1 number(s): "1215"
Test #5:
score: 10
Accepted
time: 0ms
memory: 3584kb
input:
100 251 88 95 90 39 170 75 71 718 38 37 51 92 86 622 29 46 790 85 43 175 14 65 614 2 97 123 72 28 919 9 89 158 63 89 159 55 30 297 76 4 267 94 93 56 96 85 293 69 65 539 58 49 281 85 14 997 98 15 693 72 39 73 90 47 513 100 53 642 96 28 897 14 73 790 26 14 289 90 52 699 91 84 283 56 32 480 71 24 151 9...
output:
969
result:
ok 1 number(s): "969"
Test #6:
score: 10
Accepted
time: 1ms
memory: 3712kb
input:
250 610 204 239 1 247 593 247 65 111 191 153 113 189 37 316 93 62 988 93 89 888 21 130 778 129 107 123 47 228 487 100 57 980 163 113 267 212 101 950 166 113 5 6 53 907 118 241 295 183 186 208 170 206 88 50 84 546 50 51 545 24 233 875 65 233 805 10 82 432 137 82 232 10 71 332 240 97 44 108 58 496 57 ...
output:
1544
result:
ok 1 number(s): "1544"
Test #7:
score: 10
Accepted
time: 0ms
memory: 3712kb
input:
500 1229 5 23 465 257 101 425 207 131 355 233 664 250 266 163 379 191 152 281 465 611 218 473 40 455 480 812 59 427 310 126 465 18 290 242 648 250 356 755 237 211 562 379 468 44 205 291 213 199 474 242 6 282 434 46 203 171 11 460 427 489 165 21 368 387 12 387 349 105 275 21 596 481 298 962 341 329 9...
output:
1252
result:
ok 1 number(s): "1252"
Test #8:
score: 10
Accepted
time: 0ms
memory: 3840kb
input:
1000 2450 925 987 674 703 724 780 787 532 101 418 143 102 463 431 103 481 109 104 496 854 105 497 593 106 507 493 107 508 875 565 789 511 800 565 119 108 578 499 255 9 123 872 862 1 745 991 369 788 373 241 277 987 124 278 382 125 291 601 126 387 332 127 366 72 128 378 511 129 369 389 210 799 798 42 ...
output:
762
result:
ok 1 number(s): "762"
Test #9:
score: 10
Accepted
time: 0ms
memory: 3840kb
input:
2000 4862 1935 306 1726 751 709 1643 1852 159 1388 1503 791 1881 1033 332 1360 1713 750 1656 1855 868 1439 573 758 1923 1333 593 1577 1742 112 105 1816 965 800 1560 130 10 1856 76 1735 1926 259 643 1902 301 1140 1301 475 580 180 860 1972 1236 383 238 722 242 1937 1372 282 1468 1316 95 64 522 696 132...
output:
1075
result:
ok 1 number(s): "1075"
Test #10:
score: 10
Accepted
time: 1ms
memory: 3968kb
input:
2500 6071 1760 669 2310 2380 17 2411 2373 371 2478 2411 405 2328 2492 300 538 2483 342 2310 2380 492 2262 2224 474 2202 2199 410 2215 2186 275 2154 2138 462 2186 2003 41 2121 2124 364 2029 2030 198 2125 1983 256 2042 2071 495 1895 1880 420 1862 1747 112 1963 1890 172 1890 1959 296 1926 1650 112 1651...
output:
1159
result:
ok 1 number(s): "1159"