Language: C++

#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;

//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/rope>
//using namespace __gnu_pbds;
//using namespace __gnu_cxx;
//
//template<class T> using Tree = tree<T, null_type, less<T>, rb_t_tag,t_order_statistics_node_update>;
/***********************************************/
/* Dear online judge:
 * I've read the problem, and tried to solve it.
 * Even if you don't accept my solution, you should respect my effort.
 * I hope my code compiles and gets accepted.
 *  ___  __     _______    _______      
 * |\  \|\  \  |\  ___ \  |\  ___ \     
 * \ \  \/  /|_\ \   __/| \ \   __/|    
 *  \ \   ___  \\ \  \_|/__\ \  \_|/__  
 *   \ \  \\ \  \\ \  \_|\ \\ \  \_|\ \ 
 *    \ \__\\ \__\\ \_______\\ \_______\
 *     \|__| \|__| \|_______| \|_______|
 */
const long long mod = 1000000007;
//const long long mod = 998244353;

// watch this
//using ll = long long;
//typedef long long LL;
#define ll long long
#undef ll

const int mxN = 100010;

vector<int> g[mxN];
vector<int> tree[mxN];

struct DSU {
	vector<int> p, sz;
	DSU(int N) {
		p.resize(N);
		sz.resize(N, 1);
		for (int i = 0; i < N; i++)
			p[i] = i;
	}
	int par(int x) {
		if (x == p[x])
			return x;
		return p[x] = par(p[x]);
	}
	bool mrg(int x, int y) {
		x = par(x), y = par(y);
		if (x == y)
			return false;
//		if (sz[x] < sz[y]) {
//			swap(x, y);
//		}
		p[y] = p[x];
		sz[x] += sz[y];
		return true;
	}
};

long long A[mxN], B[mxN], srt[mxN];
long long dp[mxN];
long long sum[mxN];

void dfs(int u) {
	sum[u] = B[u];
	for (auto v : tree[u])
		dfs(v), sum[u] += sum[v];
	dp[u] = max(0ll, A[u] - B[u]);
	for (auto v : tree[u]) {
		dp[u] = min(dp[u], max(dp[v], A[u] - B[u] - sum[v]));
	}
//	cerr << u << ' ' << dp[u] << '\n';
}

bool can[mxN];

int main(int argc, char** argv) {
	//#ifdef ONLINE_JUDGE
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	//#endif

	int N, M, u, v;
	cin >> N >> M;
	vector<int> ord(N);
	for (int i = 1; i <= N; i++)
		cin >> A[i] >> B[i], srt[i] = max(A[i] - B[i], 0ll), ord[i - 1] = i;
	sort(begin(ord), end(ord), [&](int a,int b) {return srt[a] < srt[b];});
//	swap(ord[1], ord[2]);
	for (int i = 0; i < M; i++) {
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	DSU dsu(N + 1);
	for (int i = 0; i < N; i++) {
		for (auto o : g[ord[i]])
			if (can[o]) {
				int p = dsu.par(o);
				if (p != ord[i])
					tree[ord[i]].push_back(p), dsu.mrg(ord[i], p);
			}
		can[ord[i]] = true;
	}
	for (int i = 1; i <= N; i++)
		if (dsu.par(i) == i)
			dfs(i), cout << dp[i] + sum[i] << '\n';
	return 0;
}

Compiler output:
In file included from /usr/include/c++/14/string:43,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:4:
/usr/include/c++/14/bits/allocator.h: In destructor 'std::_Vector_base<int, std::allocator<int> >::_Vector_impl::~_Vector_impl()':
/usr/include/c++/14/bits/allocator.h:182:7: error: inlining failed in call to 'always_inline' 'std::allocator< <template-parameter-1-1> >::~allocator() noexcept [with _Tp = int]': target specific option mismatch
  182 |       ~allocator() _GLIBCXX_NOTHROW { }
      |       ^
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53:
/usr/include/c++/14/bits/stl_vector.h:132:14: note: called from here
  132 |       struct _Vector_impl
      |              ^~~~~~~~~~~~