QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#650351 | #7883. Takeout Delivering | Yurily# | WA | 55ms | 11528kb | C++20 | 1.0kb | 2024-10-18 14:47:04 | 2024-10-18 14:47:07 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int MAXN=3e5+5,MAXM=1e6+5;
int fa[MAXN],f[MAXN],n,m;
struct edge{
int u,v,w;
};
edge e[MAXM];
int ans=2e9;
int findf(int x){
if(x==fa[x])
return fa[x];
fa[x]=findf(fa[x]);
return fa[x];
}
bool cmp(edge u,edge v){
return u.w<v.w;
}
// 快读
int read(){
int x = 0, f = 1;
char c = getchar();
while(c < '0' || c > '9'){
if(c == '-'){
f = -1;
}
c = getchar();
}
while(c >= '0' && c <= '9'){
x = x*10+c-'0';
c = getchar();
}
return x*f;
}
int main(){
n=read(),m=read();
for(int i=1;i<=m;++i){
e[i].u=read(),e[i].v=read(),e[i].w=read();
}
sort(e+1,e+1+m,cmp);
for(int i=1;i<=n;++i)
fa[i]=i;
for(int i=1;i<=m;++i){
int r1=findf(e[i].u);
int r2=findf(e[i].v);
int t1=findf(1),t2=findf(n);
if(r1!=r2){
if(r1==t1&&r2==t2||r1==r2&&r2==t1){
ans=min(ans,max(f[r1],f[r2])+e[i].w);
}
else{
fa[r2]=r1;
f[r1]=max(f[r1],e[i].w);
}
}
}
cout<<ans;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5668kb
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: 0
Accepted
time: 52ms
memory: 11528kb
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:
1999991697
result:
ok 1 number(s): "1999991697"
Test #3:
score: -100
Wrong Answer
time: 55ms
memory: 11528kb
input:
300000 299999 207226 231742 414945003 84591 210444 175968953 46327 51582 612565723 18773 141119 82562646 76139 286963 762958587 131867 224820 928900783 215240 216181 405340417 144725 290878 195350550 267216 268752 846015171 31413 255927 389339642 45219 147512 489502910 113391 215402 555706684 53359 ...
output:
2000000000
result:
wrong answer 1st numbers differ - expected: '1989898633', found: '2000000000'