Untitled

public
6shootingstar9 Apr 15, 2025 Never 27
Clone
Plaintext paste1.txt 65 lines (65 loc) | 1.48 KB
1
//https://www.xinyoudui.com/ac/contest/74700625D0006AA04E7B896/problem/7295
2
/*
3
报错信息:
4
compile error:
5
answer.code: In function ‘int main()’:
6
answer.code:37:15: error: no match for ‘operator>’ (operand types are ‘std::basic_istream<char>::__istream_type’ {aka ‘std::basic_istream<char>’} and ‘int’)
7
37 | cin>>x>y>>z;
8
| ~~~~~~^~~~~
9
| | |
10
| | int
11
| std::basic_istream<char>::__istream_type {aka std::basic_istream<char>}
12
answer.code:37:15: note: candidate: ‘operator>(int, int)’ <built-in>
13
37 | ...
14
*/
15
#include<bits/stdc++.h>
16
using namespace std;
17
const int N=10010;
18
int n;
19
struct edge
20
{
21
int v;
22
int nxt;
23
}e[N];
24
int val[N],dp[N][2],cnt,head[N];
25
void add(int u,int v)
26
{
27
e[++cnt].v=v;
28
e[cnt].nxt=head[u];
29
head[u]=cnt;
30
}
31
void dfs(int u,int fa)
32
{
33
dp[u][0]=0;
34
dp[u][1]=val[u];
35
for(int i=head[u];i;i=e[i].nxt)
36
{
37
int v=e[i].v;
38
if(v==fa)
39
continue;
40
dfs(v,u);
41
dp[u][0]+=max(dp[v][0],dp[v][1]);
42
dp[u][1]+=max(dp[v][0],dp[v][1]);
43
}
44
}
45
int main()
46
{
47
cin>>n;
48
for(int i=1;i<n;i++)
49
{
50
int x,y,z;
51
cin>>x>y>>z;
52
add(x,y);
53
add(y,x);
54
val[i]=z;
55
}
56
int ans=0;
57
for(int i=1;i<=n;i++)
58
{
59
memset(dp,0,sizeof(dp));
60
dfs(i,-1);
61
ans=max(ans,dp[i][1]);
62
}
63
cout<<ans;
64
return 0;
65
}