QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#273888 | #7883. Takeout Delivering | ucup-team2000# | WA | 109ms | 26596kb | C++20 | 1.4kb | 2023-12-03 05:18:27 | 2023-12-03 05:18:27 |
Judging History
answer
#include <bits/stdc++.h>
const int INF = 1E9 + 4;
int N, M;
std::vector<std::pair<int, int>> edge[310000];
std::vector<std::tuple<int, int, int>> tedge;
int ufs[310000];
int find(int x) {
if (ufs[x] == x) return x;
return ufs[x] = find(ufs[x]);
}
void merge(int x, int y) {
x = find(x); y = find(y);
if (x != y) ufs[x] = y;
}
int main() {
scanf("%d%d", &N, &M);
for (int i = 0; i < M; ++i) {
int u, v, c;
scanf("%d%d%d", &u, &v, &c);
edge[u].push_back({v, c});
edge[v].push_back({u, c});
tedge.push_back({c, u, v});
}
for (int i = 1; i <= N; ++i) ufs[i] = i;
std::sort(tedge.begin(), tedge.end());
int ans = INF + INF;
for (auto e: edge[1]) {
if (e.first == N) ans = std::min(ans, e.second);
}
for (int i = 0; i < (int) tedge.size(); ++i) {
int c, u, v; std::tie(c, u, v) = tedge[i];
merge(u, v);
if (find(1) == find(N)) break;
if (find(u) == find(1)) {
for (auto e: edge[u]) if (find(e.first) == find(N))
ans = std::min(ans, e.second + c);
}
if (find(v) == find(1)) {
for (auto e: edge[v]) if (find(e.first) == find(N))
ans = std::min(ans, e.second + c);
}
if (find(u) == find(N)) {
for (auto e: edge[u]) if (find(e.first) == find(1))
ans = std::min(ans, e.second + c);
}
if (find(v) == find(N)) {
for (auto e: edge[v]) if (find(e.first) == find(1))
ans = std::min(ans, e.second + c);
}
}
printf("%d\n", ans);
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 11656kb
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: 109ms
memory: 26596kb
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:
2000000008
result:
wrong answer 1st numbers differ - expected: '1999991697', found: '2000000008'