为什么我自己编译RE(第一个大样例)交上去却AC了
#include<bits/stdc++.h>
using namespace std;
const int N=500010,M=1000010;
int n,s,a,b,t,nxt[M],head[N],to[M],w[M],ipx;
long long ans,f[N];
void add(int a,int b,int t){
nxt[++ipx]=head[a];
to[ipx]=b,w[ipx]=t;
head[a]=ipx;
}
void dfs(int temp,int fa){
for(int i=head[temp];i;i=nxt[i]){
int t=to[i];
if(t==fa)continue;
dfs(t,temp);
f[temp]=max(f[temp],f[t]+w[i]);
}
for(int i=head[temp];i;i=nxt[i]){
int t=to[i];
if(t==fa)continue;
ans+=f[temp]-f[t]-w[i];
}
return ;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin>>n>>s;
for(int i=1;i<n;++i){
cin>>a>>b>>t;
add(a,b,t);
add(b,a,t);
}
dfs(s,0);
cout<<ans;
return 0;
}
哪位大佬给我说一下