QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#296161 | #7883. Takeout Delivering | ucup-team870# | WA | 128ms | 37008kb | C++14 | 1.8kb | 2024-01-02 12:20:47 | 2024-01-02 12:20:47 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i,l,r) for(int i=l; i<=r; i++)
#define per(i,r,l) for(int i=r; i>=l; i--)
#define IOS {cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);}
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int N = 300030;
struct node {
int u, v, w;
} e[1000010];
vector <P> ed[N];
int fa[N], to[N], root, b1[N], bn[N], vis1[N], visn[N];
int find(int x) {
if (x != fa[x]) {
int t = fa[x];
fa[x] = find(fa[x]);
to[x] = max(to[x], to[t]);
}
return fa[x];
}
bool cmp(node a, node b) {
return a.w < b.w;
}
void dfs(int u, int vis[], int b[], int d) {
vis[u] = 1;
b[u] = d;
for (auto [v, w]: ed[u]) {
if (!vis[v]) {
dfs(v, vis, b, max(d, w));
}
}
}
int main() {
int n, m; scanf("%d%d", &n, &m);
rep (i, 1, m) {
scanf("%d%d%d", &e[i].u, &e[i].v, &e[i].w);
}
sort(e+1, e+m+1, cmp);
int ans = 2e9;
rep (i, 1, n) fa[i] = i, b1[i] = 1e9, bn[i] = 1e9;
b1[1] = 0, bn[n] = 0, vis1[1] = 1, visn[n] = 1;
rep (i, 1, m) {
auto [u,v,w] = e[i];
if (u == 1 && v == n || u == n && v == 1) ans = min(ans, w);
ans = min(ans, w + max(b1[u], bn[v]));
ans = min(ans, w + max(bn[u], b1[v]));
int x = find(u), y = find(v);
if (x != y) {
fa[x] = y;
if (vis1[u]) dfs(v, vis1, b1, max(b1[u], w));
if (visn[u]) dfs(v, visn, bn, max(bn[u], w));
if (vis1[v]) dfs(u, vis1, b1, max(b1[v], w));
if (visn[v]) dfs(u, visn, bn, max(bn[v], w));
ed[u].push_back(P(v, w));
ed[v].push_back(P(u, w));
}
}
cout << ans;
return 0;
}
/*
4 6
1 2 2
1 3 4
1 4 7
2 3 1
2 4 3
3 4 9
*/
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 18108kb
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: 128ms
memory: 37008kb
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:
1000001925
result:
wrong answer 1st numbers differ - expected: '1999991697', found: '1000001925'