Language: C++

#include<bits/stdc++.h>
#define ll long long
#define dbg1(x) cerr<<#x<<"="<<(x)<<" "
#define dbg2(x) cerr<<#x<<"="<<(x)<<"\n"
#define dbg3(x) cerr<<#x<<"\n"
using namespace std;
#define reg register
#define pb push_back
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
	return x*f;
}
const int MN=1e5+5;
int N,M,A[MN],B[MN],id[MN],par[MN];
ll f[MN],sz[MN],C[MN];
vector<int> G[MN],T[MN];
bool cmp(int x,int y){return C[x]<C[y];}
int getf(int x){return x==par[x]?x:getf(par[x]);}
void rw(ll &x,ll y){if(y<x)x=y;}
void dfs(int x)
{
	#define y T[x][i]
	reg int i;sz[x]=B[x];f[x]=1e15;
	if(!T[x].size())return (void)(f[x]=B[x]+C[x]);
	for(i=T[x].size()-1;~i;--i)dfs(y),sz[x]+=sz[y];
	for(i=T[x].size()-1;~i;--i)rw(f[x],sz[x]-sz[y]+max(C[x],f[y]));
	#undef y
}
int main()
{
	N=read();M=read();
	reg int i,j,x,y;
	for(i=1;i<=N;++i) par[i]=id[i]=i;
	for(i=1;i<=N;++i) A[i]=read(),B[i]=read(),C[i]=max(A[i]-B[i],0LL);
	for(i=1;i<=M;++i) x=read(),y=read(),G[x].pb(y),G[y].pb(x);
	std::sort(id+1,id+N+1,cmp);
	for(i=1;i<=N;++i)for(j=G[x=id[i]].size()-1;~j;--j)
	{
		y=getf(G[x][j]);
		if(y!=x&&C[y]<=C[x]) par[y]=x,T[x].pb(y);
	}
	dfs(id[N]);
	return 0*printf("%d\n",f[id[N]]);
}

Compiler output:
a.cc: In function 'void dfs(int)':
a.cc:26:17: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   26 |         reg int i;sz[x]=B[x];f[x]=1e15;
      |                 ^
a.cc: In function 'int main()':
a.cc:35:17: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   35 |         reg int i,j,x,y;
      |                 ^
a.cc:35:19: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   35 |         reg int i,j,x,y;
      |                   ^
a.cc:35:21: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   35 |         reg int i,j,x,y;
      |                     ^
a.cc:35:23: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   35 |         reg int i,j,x,y;
      |                       ^
a.cc:37:59: error: no matching function for call to 'max(int, long long int)'
   37 |         for(i=1;i<=N;++i) A[i]=read(),B[i]=read(),C[i]=max(A[i]-B[i],0LL);
      |                                                        ~~~^~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/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:37:59: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   37 |         for(i=1;i<=N;++i) A[i]=read(),B[i]=read(),C[i]=max(A[i]-B[i],0LL);
      |                                                        ~~~^~~~~~~~~~~~~~~
/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
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:37:59: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   37 |         for(i=1;i<=N;++i) A[i]=read(),B[i]=read(),C[i]=max(A[i]-B[i],0LL);
      |                                                        ~~~^~~~~~~~~~~~~~~