跳到正文

个人记录

陈老师求条

_starry_night约 2 分钟
原文
文章信息与版本

文章信息

收录
2026年3月19日
更新
2026年3月20日
篇幅
约 2 分钟

版本

  1. v1当前
C++
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int N=1e5+25;
struct node{
	int y,w;
};
int n,maxx,mi;
int dp1[N],dp2[N];
vector<node>G[N];
void dfs(int u,int pre,int mn){
	if(mn>maxx){
		maxx=mn;
		mi=u;
	}
	for(int i=0;i<G[u].size();i++){
		if(G[u][i].y==pre)continue;
		dfs(G[u][i].y,u,mn+G[u][i].w);
	}
	return ;
}
signed main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	for(int i=1;i<n;i++)
    {
    	int u,v,w;
    	cin>>u>>v>>w;
    	G[u].push_back({v,w});
    	G[v].push_back({u,w});
	}
	dfs(1,0,0);
	dfs(mi,0,0);
	cout<<maxx*10+maxx*(maxx+1)*10/2;
	return 0;
}

这是大臣的旅费不知道为啥答案总是大了一点,想不出拿错了qwq

原文