第一个点下下来的数据测的是对的,可是测评错了。。。是什么需要注意的东西吗?求助!
输入
10
4 5 1
2 1 1
7 5 1
10 1 1
6 5 1
9 7 1
3 2 1
8 6 1
10 9 1
4 3 1
输出
3.5
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<set>
#include<vector>
using namespace std;
#define int long long
#define R register
#define debug printf("zjy ")
#define ld double
int read(){
int a=0,b=1;char c=getchar();
while(!isdigit(c)){if(c=='-')b=-1;c=getchar();}
while(isdigit(c)){a=a*10+c-'0';c=getchar();}
return a*b;
}
void write(int x){
if(x<0){putchar('-');x=-x;}
if(x<=9){putchar(x+'0');return;}
write(x/10);putchar(x%10+'0');
}
void writesp(int x){
write(x);putchar(' ');
}
void writeln(int x){
write(x);putchar('\n');
}
const int N=1e5+50,M=2e5+50,inf=1e17;
int n,tot,h[N],ver[M],nx[M],ed[M],vis[N],cnt,lin[N],
ans,d[N][2],w[M],dis[M],g[M],pre[N],nxt[N],bpre[N],bnxt[N],
cpre[N],cnxt[N];
void add(int u,int v,int z){
ver[++tot]=v;ed[tot]=z;
nx[tot]=h[u];h[u]=tot;
}
bool dfs1(int x,int fa){
if(vis[x]==1){
vis[x]=2;lin[++cnt]=x;return 1;
}
vis[x]=1;
for(R int i=h[x],v;i;i=nx[i]){
v=ver[i];
if(v==fa)continue;
if(dfs1(v,x)){
if(lin[1]==x){
dis[cnt+1]=ed[i];
return 0;
}
else{
vis[x]=2;
lin[++cnt]=x;
dis[cnt]=dis[cnt-1]+ed[i];
return 1;
}
}
}
}
void dfs2(int x,int fa){
for(R int i=h[x],v;i;i=nx[i]){
v=ver[i];
if(v==fa||vis[v]==2)continue;
dfs2(v,x);
if(d[v][0]+ed[i]>d[x][0]){
d[x][1]=d[x][0];
d[x][0]=d[v][0]+ed[i];
}
else{
if(d[v][0]+ed[i]>d[x][1]){
d[x][1]=d[v][0]+ed[i];
}
}
}
ans=max(ans,d[x][0]+d[x][1]);
}
int val,mx1,mx2;
void solve(){
dfs1(1,0);
cpre[0]=inf;
for(R int i=1;i<=cnt;i++){
dfs2(lin[i],0);
w[i]=d[lin[i]][0];
pre[i]=max(pre[i-1],dis[i]+w[i]);
cpre[i]=min(cpre[i-1],dis[i]-w[i]);
if(i>=2)bpre[i]=max(bpre[i-1],dis[i]+w[i]-cpre[i-1]);
}
for(R int i=cnt;i>=1;i--){
nxt[i]=max(nxt[i+1],dis[cnt]-dis[i]+w[i]);
cnxt[i]=max(cnxt[i+1],dis[i]+w[i]);
if(i<=cnt-1)bnxt[i]=max(bnxt[i+1],cnxt[i+1]-dis[i]+w[i]);
}
val=inf;
for(R int i=1;i<=cnt-1;i++){
val=min(val,max(pre[i]+nxt[i+1]+dis[cnt+1],max(bpre[i],bnxt[i+1])));
}
ans=max(ans,val);
}
ld zxt;
signed main(){
n=read();
for(R int i=1,u,v,z;i<=n;i++){
u=read();v=read();z=read();
add(u,v,z);add(v,u,z);
}
solve();
zxt=1.0*ans/2;
printf("%.1lf\n",zxt);
return 0;
}