QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#650579 | #7883. Takeout Delivering | Yurily# | WA | 107ms | 40236kb | C++20 | 1.6kb | 2024-10-18 15:39:21 | 2024-10-18 15:39:21 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int MAXN=3e5+5,MAXM=1e6+5;
int fa[MAXN],n,m;
long long d[MAXN];
struct edge{
int u,v;
long long w;
};
vector<edge> g[MAXN];
edge e[MAXM];
long long ans=1e15;
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;
}
void addedge(int u,int v,int w){
edge tmp;
tmp.v=v,tmp.w=w;
g[u].push_back(tmp);
}
void dfs(int u,int fat,long long cur){
d[u]=max(d[fat],cur);
for(auto i=g[u].begin();i!=g[u].end();++i){
int v=(*i).v,w=(*i).w;
if(v==fat)
continue;
dfs(v,u,w);
}
}
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(d[e[i].u],d[e[i].v])+e[i].w);
}
else{
fa[r2]=r1;
addedge(e[i].u,e[i].v,e[i].w);
addedge(e[i].v,e[i].u,e[i].w);
if(r1==t1||r1==t2){
dfs(e[i].v,e[i].u,e[i].w);
}
if(r2==t1||r2==t2){
dfs(e[i].u,e[i].v,e[i].w);
}
}
}
}
/* for(int i=1;i<=n;++i)
cout<<d[i]<<" ";
cout<<endl;*/
cout<<ans;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5604kb
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: 107ms
memory: 40236kb
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: 104ms
memory: 34724kb
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:
1000000000000000
result:
wrong answer 1st numbers differ - expected: '1989898633', found: '1000000000000000'