记录编号 205470 评测结果 AAAAAAAAAA
题目名称 不平凡的引线 最终得分 100
用户昵称 Gravatardydxh 是否通过 通过
代码语言 C++ 运行时间 0.392 s
提交时间 2015-11-05 14:04:14 内存使用 5.28 MiB
显示代码纯文本
/*
Problem:cogs2095;
Language:c++;
by dydxh;
2015.11.05;
*/
#include<iostream>
#include<cstdio>
#include<set>
#include<map>
#include<queue>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<utility>
#include<ctime>
#include<cstdlib>
#include<bitset>
#include<string>
#define ll long long
#define ull unsigned long long
using namespace std;
const int oo=2000000000;
const int maxn=100005;
int n,m,root,len;
int D[maxn],linkk[maxn];
ll T[maxn];
struct EDGEE{
	int x,y,v;
}eg[maxn];
struct edge{
	int y,next,v;
}e[maxn<<1];
inline int myabs(const int &a){return a>=0?a:-a;}
inline void myswap(int &a,int &b){int t=a;a=b,b=t;}
inline int mymax(const int &a,const int &b){return a>b?a:b;}
inline int mymin(const int &a,const int &b){return a>b?b:a;}
inline int read(){
	int x=0;bool flag=0;char ch=getchar();
	while(ch>'9' || ch<'0') {if(ch=='-') flag=1;ch=getchar();}
	while(ch>='0' && ch<='9') {x=x*10+ch-'0';ch=getchar();}
	return flag?-x:x;
}
void insert(int a,int b,int c){
	e[++len].next=linkk[a];
	linkk[a]=len,e[len].y=b,e[len].v=c;
	e[++len].next=linkk[b];
	linkk[b]=len,e[len].y=a,e[len].v=c;
}
void Dfs_Down_To_Up(int x,int Father){
	T[x]=oo;
	for(int i=linkk[x];i;i=e[i].next){
		int tn=e[i].y;
		if(tn==Father) continue;
		Dfs_Down_To_Up(tn,x);
		if(T[tn]+e[i].v<T[x])
			T[x]=T[tn]+e[i].v;
	}
	if(D[x]==1) T[x]=0;
}
void Dfs_Up_To_Down(int x,int Father,ll Tim){
	if(T[x]>Tim) T[x]=Tim;
	for(int i=linkk[x];i;i=e[i].next){
		int tn=e[i].y;
		if(tn==Father) continue;
		Dfs_Up_To_Down(tn,x,T[x]+e[i].v);
	}
}
int main()
{
	//freopen("cc.in","r",stdin);
	freopen("firelead.in","r",stdin);
	freopen("firelead.out","w",stdout);
	m=read(),n=m+1;
	for(int i=1;i<=m;i++){
		eg[i].x=read(),eg[i].y=read(),eg[i].v=read();
		insert(eg[i].x,eg[i].y,eg[i].v);
		D[eg[i].x]++,D[eg[i].y]++;
	}
	for(int i=1;i<=n;i++)
		if(D[i]==1){
			root=i;
			break;
		}
	Dfs_Down_To_Up(root,0);
	Dfs_Up_To_Down(root,0,0);
	double ans=0;
	for(int i=1;i<=m;i++){
		int x=eg[i].x,y=eg[i].y,v=eg[i].v;
		if(T[x]<T[y]) myswap(x,y);
		if(T[x]-T[y]==v){
			if(ans<T[x])
				ans=T[x];
		}
		else if(T[x]+1.0*(v-(T[x]-T[y]))/2>ans)
			ans=T[x]+1.0*(v-(T[x]-T[y]))/2;
	}
	printf("%.1lf\n",ans);
	return 0;
}