QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#283357 | #7883. Takeout Delivering | wxy | WA | 129ms | 42796kb | C++14 | 2.1kb | 2023-12-14 15:25:28 | 2023-12-14 15:25:29 |
Judging History
answer
// start time : 15 : 17
#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 fi first
#define se second
#define pb push_back
#define mp std::make_pair
#define gin std::cin
#define prt std::cout
#define edl std::endl
namespace Main {
const int N = 3e5 + 5;
int n,m,dist1[N],distn[N],val[N],val1[N],valn[N],fa[N];
std::vector<std::pair<int,int>> G[N];
struct Edge {
int u,v,w;
Edge() {}
Edge(int _u,int _v,int _w) {
u = _u; v = _v; w = _w;
}
bool operator<(const Edge &B) const {
return w < B.w;
}
} ;
int get(int x) { return fa[x] == x ? x : fa[x] = get(fa[x]); }
void merge(int x,int y) {
fa[get(x)] = fa[get(y)];
}
void dfs1(int x,int fa) {
for (auto e : G[x]) {
int v = e.first;
if (v == fa) continue;
dist1[v] = std::max(dist1[x],e.second);
val1[v] = std::max(val1[x],val[e.second]);
dfs1(v,x);
}
}
void dfs2(int x,int fa) {
for (auto e : G[x]) {
int v = e.first;
if (v == fa) continue;
distn[v] = std::max(distn[x],e.second);
valn[v] = std::max(valn[x],val[e.second]);
dfs2(v,x);
}
}
std::vector<Edge> edges;
void main() {
scanf("%d%d",&n,&m);
rep(i,1,m) {
int u,v,w;
scanf("%d%d%d",&u,&v,&w);
edges.push_back(Edge(u,v,w));
}
rep(i,1,n) {
fa[i] = i;
}
std::sort(edges.begin(),edges.end());
int cur = 0;
for (auto e : edges) {
int u = e.u,v = e.v,w = e.w; ++ cur; val[cur] = w;
if (get(u) == get(v)) continue;
merge(u,v); G[u].push_back({v,cur}); G[v].push_back({u,cur});
}
dfs1(1,-1); dfs2(n,-1);
int ans = INT_MAX;
cur = 0;
for (auto e : edges) {
++ cur;
int u = e.u,v = e.v,w = e.w;
if (dist1[u] < cur && distn[v] < cur) {
ans = std::min(ans,w + val1[u] + valn[v]);
}
if (dist1[v] < cur && distn[u] < cur) {
ans = std::min(ans,w + val1[v] + valn[u]);
}
}
prt << ans;
}
} signed main() { Main::main(); return 0; }
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 14304kb
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: 129ms
memory: 42796kb
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:
-1294995448
result:
wrong answer 1st numbers differ - expected: '1999991697', found: '-1294995448'