QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#288305 | #7883. Takeout Delivering | ckiseki# | WA | 137ms | 39268kb | C++20 | 1.9kb | 2023-12-22 14:43:21 | 2023-12-22 14:43:21 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define all(x) begin(x), end(x)
#ifdef CKISEKI
#include <experimental/iterator>
#define debug(a...) debug_(#a, a)
#define orange(a...) orange_(#a, a)
void debug_(auto s, auto ...a) {
cerr << "\e[1;32m(" << s << ") = (";
int f = 0;
(..., (cerr << (f++ ? ", " : "") << a));
cerr << ")\e[0m\n";
}
void orange_(auto s, auto L, auto R) {
cerr << "\e[1;33m[ " << s << " ] = [ ";
using namespace experimental;
copy(L, R, make_ostream_joiner(cerr, ", "));
cerr << " ]\e[0m\n";
}
#else
#define safe ((void)0)
#define debug(...) safe
#define orange(...) safe
#endif
struct Dsu {
vector<int> pa, rk;
Dsu(int n) : pa(n), rk(n) {
iota(all(pa), 0);
}
int anc(int x) {
return x==pa[x] ? x : pa[x]=anc(pa[x]);
}
bool join(int x, int y) {
x = anc(x);
y = anc(y);
if (x == y) return false;
if (rk[x] < rk[y]) swap(x, y);
if (rk[x] == rk[y]) ++rk[x];
pa[y] = x;
return true;
}
};
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n, m;
cin >> n >> m;
int ans = 2e9;
vector<tuple<int,int,int>> e;
for (int i = 0; i < m; i++) {
int u, v, w;
cin >> u >> v >> w;
--u, --v;
e.emplace_back(w, u, v);
tie(u, v) = minmax(u, v);
if (u == 0 && v == n - 1)
ans = min(ans, w);
}
ranges::sort(e);
Dsu dsu(n);
vector<vector<pair<int,int>>> g(n);
for (auto [w, u, v] : e) {
if (dsu.join(u, v)) {
g[u].emplace_back(w, v);
g[v].emplace_back(w, u);
}
}
const auto dfs = [&](auto self, vector<int> &d, int i, int f) -> void {
for (auto [w, j] : g[i]) {
if (j == f) continue;
d[j] = max(d[i], w);
self(self, d, j, i);
}
};
vector<int> d1(n), dn(n);
dfs(dfs, d1, 0, -1);
dfs(dfs, dn, n - 1, -1);
orange(all(d1));
orange(all(dn));
for (int i = 0; i < n; i++) {
if (i == 0 || i == n - 1) continue;
ans = min(ans, d1[i] + dn[i]);
}
cout << ans << '\n';
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3576kb
input:
4 6 1 2 2 1 3 4 1 4 7 2 3 1 2 4 3 3 4 9
output:
5
result:
ok 1 number(s): "5"
Test #2:
score: -100
Wrong Answer
time: 137ms
memory: 39268kb
input:
300000 299999 80516 80517 597830404 110190 110191 82173886 218008 218009 954561262 250110 250111 942489774 66540 66541 156425292 34947 34948 239499776 273789 273790 453201232 84428 84429 439418398 98599 98600 326095035 55636 55637 355015760 158611 158612 684292473 43331 43332 43265001 171621 171622 ...
output:
1356916107
result:
wrong answer 1st numbers differ - expected: '1999991697', found: '1356916107'