/ Randle /

记录详情

Accepted

/in/foo.cc: In function 'void dfs(int, int)':
/in/foo.cc:17:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<f[x].size();i++){
              ~^~~~~~~~~~~~
# 状态 耗时 内存占用
#1 Accepted 2ms 1.449 MiB
#2 Accepted 2ms 1.441 MiB
#3 Accepted 2ms 1.445 MiB
#4 Accepted 2ms 1.457 MiB
#5 Accepted 2ms 1.57 MiB
#6 Accepted 2ms 1.57 MiB
#7 Accepted 2ms 1.582 MiB
#8 Accepted 3ms 1.695 MiB
#9 Accepted 15ms 3.062 MiB
#10 Accepted 19ms 3.453 MiB

代码

#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
inline int read(void){
	int x=0,f=1; char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar()) if(ch=='-') f=-1;
	for(;ch>='0'&&ch<='9';x=(x<<3)+(x<<1)+ch-'0',ch=getchar());
	return x*f;
}
const int maxn=50009;
struct LJM{
	int to,w;
}; vector<LJM>f[maxn];
int dis[maxn];
void dfs(int x,int fa){
	for(int i=0;i<f[x].size();i++){
		int to=f[x][i].to;
		if(to==fa) continue;
		dfs(to,x);
		dis[x]=max(dis[x],dis[to]+f[x][i].w);
	}
}
int main(int argc,char const *argv[]){
	int n=read(),sum=0;
	for(int i=1;i<n;i++){
		int	a=read(),b=read(),c=read();
		sum+=c;
		f[a].push_back((LJM){b,c});
		f[b].push_back((LJM){a,c});
	}
	dfs(1,-1);
	cout<<sum*2-dis[1]<<endl;
	return 0;
}

信息

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