Language: C++

#include <iostream>
#include <cstdio>
#include <cstring>
 
using namespace std;
 
const int MAXN = 2e5 + 10;
long long oo = 100000000000007ll;
 
class Edges{
public:
	int next , to , v;
};
Edges edge[MAXN];
int fa[MAXN] , first[MAXN];
int n , te = 0 , ans = 0;
void add(int s , int t , int v){
	++ te;
	edge[te].to = t;
	edge[te].next = first[s];
	edge[te].v = v;
	first[s] = te;
}
long long work(int now){
	long long maxn = 0 , t = oo;
	for(int e = first[now] ; e ; e = edge[e].next){
		int to = edge[e].to , ret = work(to);
		maxn += ret + edge[e].v;
		t = min(ret + edge[e].v , t);
	}
	ans = max(ans , maxn);
	if(t == oo) t = 0;
	return t;
}
int main(){
	ios::sync_with_stdio(0);
	cin >> n;
	for(int i = 2 ; i <= n ; ++ i){
		int a , v;
		cin >> a >> v;
		add(a , i , v);
	}
	work(1);
	cout << ans << endl;
	return 0;
}

Compiler output:
a.cc: In function 'long long int work(int)':
a.cc:29:24: error: no matching function for call to 'min(int, long long int&)'
   29 |                 t = min(ret + edge[e].v , t);
      |                     ~~~^~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:29:24: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   29 |                 t = min(ret + edge[e].v , t);
      |                     ~~~^~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
a.cc:31:18: error: no matching function for call to 'max(int&, long long int&)'
   31 |         ans = max(ans , maxn);
      |               ~~~^~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:31:18: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   31 |         ans = max(ans , maxn);
      |               ~~~^~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided