Language: C++


#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;

int N, K;
vector<int> e[100000], v[100000]; /*eは辺のメモ、vは整数min + iが書かれている頂点はどこかのメモ*/
int a[100000],vp[100000],P[100000];/*aは実際に書かれている整数のメモ*/
int min;


int main() {
	int i,j,k,v1,v2;

	scanf("%d", &N);

	for (i = 0; i < N - 1; i++) {
		scanf("%d %d", &v1, &v2);
		e[v1 - 1].push_back(v2 - 1);
		e[v2 - 1].push_back(v1 - 1);
	}

	for (i = 0; i < N; i++) {
		a[i] = -1;
	}

	scanf("%d", &K);
	min = 1000000;
	for (i = 0; i < K; i++) {
		scanf("%d %d", &vp[i], &P[i]);
		if (min > P[i]) { min = P[i]; }
	}

	for (i = 0; i < K; i++) {
		if (P[i] - min >= N) { printf("No\n"); return 0; }
		a[vp[i] - 1] = P[i];
		v[P[i] - min].push_back(vp[i] - 1);
	}

	for (i = 0; i < N; i++) {
		for (int j : v[i]) {/*整数min + iが書かれたすべての頂点jについて、*/
			for (int k : e[j]) {/*jと隣接するすべての頂点について、*/
				if (a[k] == -1) {
					a[k] = min + i + 1;
					v[i + 1].push_back(k);
				}
				else if ((a[k] != min + i + 1) && (a[k] != min +  i - 1)) {
					printf("No\n"); return 0;
				}
			}
		}
	}
	printf("Yes\n");
	for (i = 0; i < N; i++) {
		printf("%d\n", a[i]);
	}
	return 0;

}

Compiler output:
a.cc: In function 'int main()':
a.cc:29:9: error: reference to 'min' is ambiguous
   29 |         min = 1000000;
      |         ^~~
In file included from /usr/include/c++/14/vector:62,
                 from a.cc:4:
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidates are: '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:233:5: note:                 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
a.cc:10:5: note:                 'int min'
   10 | int min;
      |     ^~~
a.cc:32:21: error: reference to 'min' is ambiguous
   32 |                 if (min > P[i]) { min = P[i]; }
      |                     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidates are: '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:233:5: note:                 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
a.cc:10:5: note:                 'int min'
   10 | int min;
      |     ^~~
a.cc:32:35: error: reference to 'min' is ambiguous
   32 |                 if (min > P[i]) { min = P[i]; }
      |                                   ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidates are: '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:233:5: note:                 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
a.cc:10:5: note:                 'int min'
   10 | int min;
      |     ^~~
a.cc:36:28: error: reference to 'min' is ambiguous
   36 |                 if (P[i] - min >= N) { printf("No\n"); return 0; }
      |                            ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidates are: '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:233:5: note:                 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
a.cc:10:5: note:                 'int min'
   10 | int min;
      |     ^~~
a.cc:38:26: error: reference to 'min' is ambiguous
   38 |                 v[P[i] - min].push_back(vp[i] - 1);
      |                          ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidates are: '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:233:5: note:                 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
a.cc:10:5: note:                 'int min'
   10 | int min;
      |     ^~~
a.cc:45:48: error: reference to 'min' is ambiguous
   45 |                                         a[k] = min + i + 1;
      |                                                ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidates are: '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:233:5: note:                 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
a.cc:10:5: note:                 'int min'
   10 | int min;
      |     ^~~
a.cc:48:51: error: reference to 'min' is ambiguous
   48 |                                 else if ((a[k] != min + i + 1) && (a[k] != min +  i - 1)) {
      |                                                   ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidates are: '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:233:5: note:                 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
a.cc:10:5: note:                 'int min'
   10 | int min;
      |     ^~~
a.cc:48:76: error: reference to 'min' is ambiguous
   48 |                                 else if ((a[k] != min + i + 1) && (a[k] != min +  i - 1)) {
      |                                                                            ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidates are: '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:233:5: note:                 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
a.cc:10:5: note:                 'int min'
   10 | int min;
      |     ^~~