/ Randle /

记录详情

Accepted

/in/foo.cc: In function 'void DFS(int, int)':
/in/foo.cc:16:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<map[x].size();i++)
              ~^~~~~~~~~~~~~~
/in/foo.cc: At global scope:
/in/foo.cc:24:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
# 状态 耗时 内存占用
#1 Accepted 4ms 1.375 MiB
#2 Accepted 4ms 1.375 MiB
#3 Accepted 4ms 1.375 MiB
#4 Accepted 4ms 1.375 MiB
#5 Accepted 5ms 1.375 MiB
#6 Accepted 5ms 1.375 MiB
#7 Accepted 5ms 1.473 MiB
#8 Accepted 7ms 1.625 MiB
#9 Accepted 44ms 3.082 MiB
#10 Accepted 54ms 3.473 MiB

代码

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>

using namespace std;
int n,ans=0;
struct node
{
	int t,w;
};
vector<node> map[50001];
int dis[50001];
void DFS(int x,int fa)
{
	for(int i=0;i<map[x].size();i++)
	{
		int to=map[x][i].t;
		if(to==fa)	continue;
		DFS(to,x);
		dis[x]=max(dis[x],dis[to]+map[x][i].w);
	}
}
main()
{
	int i,a,b,c;
	cin>>n;
	for(i=1;i<n;i++)
	{
		cin>>a>>b>>c;
		ans+=2*c;
		map[a].push_back((node){b,c});
		map[b].push_back((node){a,c});
	}
	DFS(1,-1);
	cout<<ans-dis[1];
}

信息

递交者
类型
递交
题目
游 T2
题目数据
下载
语言
C++
递交时间
2017-09-09 16:23:41
评测时间
2017-09-09 16:23:41
评测机
分数
10
总耗时
140ms
峰值内存
3.473 MiB