Language: C++

#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<vector>
using namespace std;
typedef long long s64;

const int ONE = 200005;
const int INF = ONE;

int get()
{
		int res = 1, Q = 1; char c;
		while( (c = getchar()) < 48 || c > 57)
			if(c == '-') Q = -1;
		if(Q) res = c - 48;
		while( (c = getchar()) >= 48 && c <= 57)
			res = res * 10 + c - 48;
		return res * Q;
}

struct power
{
		int l, r;
}val[ONE];

int n, k;
int x, y;
int next[ONE], first[ONE], go[ONE], tot;

void Add(int u, int v)
{
		next[++tot] = first[u], first[u] = tot, go[tot] = v;
		next[++tot] = first[v], first[v] = tot, go[tot] = u;
}

void dfs1(int u, int father)
{
		for(int e = first[u]; e; e = next[e])
		{
			int v = go[e];
			if(v == father) continue;
			dfs1(v, u);
			val[u].l = max(val[u].l, val[v].l - 1);
			val[u].r = min(val[u].r, val[v].r + 1);
			if(val[u].l > val[u].r) {printf("No"); exit(0);}
		}
}

int A[ONE];

void dfs2(int u, int father)
{
		if(u != 1)
			if(val[u].l <= A[father] - 1 && A[father] - 1 <= val[u].r) A[u] = A[father] - 1;
			else
			if(val[u].l <= A[father] + 1 && A[father] + 1 <= val[u].r) A[u] = A[father] + 1;
			else
			if(val[u].l <= A[father] && A[father] <= val[u].r) A[u] = A[father];
		for(int e = first[u]; e; e = next[e])
		{
			int v = go[e];
			if(v == father) continue;
			dfs2(v, u);
		}
}

int main()
{
		n = get();
		for(int i = 1; i < n; i++) x = get(), y = get(), Add(x, y);
		for(int i = 1; i <= n; i++) val[i] = (power){0, INF};
		k = get();
		for(int i = 1; i <= k; i++) x = get(), y = get(), val[x] = (power){y, y};

		dfs1(1, 0);
		A[1] = (val[1].l + val[1].r) / 2;
		dfs2(1, 0);

		printf("Yes\n");
		for(int i = 1; i <= n; i++)
			printf("%d\n", A[i]);
}

Compiler output:
a.cc: In function 'void Add(int, int)':
a.cc:37:17: error: reference to 'next' is ambiguous
   37 |                 next[++tot] = first[u], first[u] = tot, go[tot] = v;
      |                 ^~~~
In file included from /usr/include/c++/14/string:47,
                 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_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:33:5: note:                 'int next [200005]'
   33 | int next[ONE], first[ONE], go[ONE], tot;
      |     ^~~~
a.cc:38:17: error: reference to 'next' is ambiguous
   38 |                 next[++tot] = first[v], first[v] = tot, go[tot] = u;
      |                 ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:33:5: note:                 'int next [200005]'
   33 | int next[ONE], first[ONE], go[ONE], tot;
      |     ^~~~
a.cc: In function 'void dfs1(int, int)':
a.cc:43:46: error: reference to 'next' is ambiguous
   43 |                 for(int e = first[u]; e; e = next[e])
      |                                              ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:33:5: note:                 'int next [200005]'
   33 | int next[ONE], first[ONE], go[ONE], tot;
      |     ^~~~
a.cc: In function 'void dfs2(int, int)':
a.cc:64:46: error: reference to 'next' is ambiguous
   64 |                 for(int e = first[u]; e; e = next[e])
      |                                              ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:33:5: note:                 'int next [200005]'
   33 | int next[ONE], first[ONE], go[ONE], tot;
      |     ^~~~