QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#273898 | #7883. Takeout Delivering | ucup-team2000# | WA | 112ms | 28176kb | C++20 | 1.2kb | 2023-12-03 05:43:37 | 2023-12-03 05:43:38 |
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 sufs[2][310000];
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;
sufs[0][y] = std::min(sufs[0][x], sufs[0][y]);
sufs[1][y] = std::min(sufs[1][x], sufs[1][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, sufs[0][i] = sufs[1][i] = INF;
for (auto e: edge[1]) {
sufs[0][e.first] = e.second;
}
for (auto e: edge[N]) {
sufs[1][e.first] = e.second;
}
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;
ans = std::min(ans, c + sufs[1][find(1)]);
ans = std::min(ans, c + sufs[0][find(N)]);
}
printf("%d\n", ans);
}
详细
Test #1:
score: 100
Accepted
time: 3ms
memory: 13368kb
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: 112ms
memory: 28176kb
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:
1000001929
result:
wrong answer 1st numbers differ - expected: '1999991697', found: '1000001929'