/ Randle /

记录详情

Wrong Answer


  
# 状态 耗时 内存占用
#1 Wrong Answer 2ms 352.0 KiB
#2 Wrong Answer 2ms 256.0 KiB
#3 Wrong Answer 1ms 256.0 KiB
#4 Wrong Answer 3ms 348.0 KiB
#5 Wrong Answer 3ms 256.0 KiB
#6 Wrong Answer 3ms 256.0 KiB
#7 Wrong Answer 1ms 352.0 KiB
#8 Wrong Answer 2ms 292.0 KiB
#9 Wrong Answer 2ms 364.0 KiB
#10 Wrong Answer 2ms 340.0 KiB

代码

#include<iostream>
#include<cstring>
#define maxn 50001
using namespace std;
struct node
{
	int x,y;
	int len;
};
node a[maxn];
int n,dis[maxn];
long long ans=0;
int main()
{
	freopen("tour.in.txt","r",stdin);
	freopen("tour.out.txt","w",stdout);
	int MAX=0;
	cin>>n;
	for(int i=1;i<=n;i++)
	dis[i]=100000;
	for(int i=1;i<n;i++)
	{
		cin>>a[i].x>>a[i].y>>a[i].len;
		ans+=a[i].len*2;
	}
	dis[1]=0;
	//for(int i=1;i<=n;i++)
	//cout<<"dis["<<i<<"]="<<dis[i]<<endl;
	for(int o=1;o<=n;o++)
	{
		bool mt=false;
	    for(int i=1;i<=n;i++)
    	{
	    	for(int j=1;j<=n;j++)
	    	{
		    	if(a[i].x==j&&dis[a[i].y]!=100000)
		    	{
			    	if(dis[j]>dis[a[i].y]+a[i].len)
			    	{
			    		dis[j]=dis[a[i].y]+a[i].len;
			    		mt=true;
					}
			    }
			    else if(a[i].y==j&&dis[a[i].x]!=100000)
			    {
				    if(dis[j]>dis[a[i].x]+a[i].len)
				    {
				    	dis[j]=dis[a[i].x]+a[i].len;
				    	mt=true;
					}
			    }
	    	}
	    }
	    if(!mt)
		break;
	}
	for(int i=1;i<=n;i++)
	{
		//cout<<"dis["<<i<<"]="<<dis[i]<<endl;
	    if(dis[i]>MAX)
	    MAX=dis[i];
	}
	//cout<<"ans="<<ans<<"  MAX="<<MAX<<endl;
	cout<<ans-MAX<<endl;
	return 0;
}

信息

递交者
类型
递交
题目
游 T2
题目数据
下载
语言
C++
递交时间
2017-09-09 15:46:44
评测时间
2017-09-09 15:46:44
评测机
分数
0
总耗时
27ms
峰值内存
364.0 KiB