暴毙,不知道是存图还是哪里搞错了
QWQ
by 谬悠 @ 2019-10-22 00:17:22
work函数最后的循环以修复QWQ
by 谬悠 @ 2019-10-22 00:18:54
请问dfs函数哪里错了啊
by 谬悠 @ 2019-10-22 00:20:34
深夜别刷题
by hly1204 @ 2019-10-22 04:13:56
有人吗
by 山海无风 @ 2019-10-22 06:45:47
~~晚上好好养肝啊~~
by 羽儇 @ 2019-10-22 06:49:08
```cpp
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define int long long
int n,m;
int dep[200005],deep[200005],fir[200005],nex[400005],to[400005],w[400005],tot,ans;
inline void add(int u,int v,int d){
to[++tot]=v;
nex[tot]=fir[u];
fir[u]=tot;
w[tot]=d;
}
void getdep(int x,int fa){
for(int i=fir[x];i;i=nex[i]){
if(to[i]!=fa){
dep[to[i]]=dep[x]+w[i];
getdep(to[i],x);
}
}
}
void qiguai(int x,int fa){
for(int i=fir[x];i;i=nex[i]){
if(to[i]!=fa){
deep[to[i]]=deep[x]+w[i];
getdep(to[i],x);
}
}
}
void work(){
getdep(1,0);
int x=1;
for(int i=2;i<=m;i++)if(dep[i]>dep[x])x=i;
memset(dep,0,sizeof(dep));
getdep(x,0);
int y=1;
for(int i=2;i<=m;i++)if(dep[i]>dep[y])y=i;
qiguai(y,0);
int ans=0;
for(int i=1;i<=m;i++){
ans=max(ans,min(dep[i],deep[i]));
}
cout<<ans+dep[y]<<endl;
}
main(){
cin>>m>>n;
for(int i=1,x,y,z;i<=n;i++){
scanf("%lld%lld%lld",&x,&y,&z);
add(x,y,z);
add(y,x,z);
}
work();
}
```
by 谬悠 @ 2019-10-22 07:53:27
过样例惹QWQ
by 谬悠 @ 2019-10-22 07:54:20
@[羽儇](/space/show?uid=116162) 窝太菜了嘛QAQ
by 谬悠 @ 2019-10-22 07:55:01
有人吗QAQ
by 谬悠 @ 2019-10-22 14:13:41