Language: C++

#include<bits/stdc++.h>
#define INF 987654321
#define N 100005
using namespace std;
struct A{
    int num,lef,rig;
   /// lef,rig는 가능한 구간이라고 하자
} s[N];
vector<int> V[N];
int n,m,ai[N],bi[N],visit[N],visit2[N];
void dfs(int from)
{
    int to,i,st,ed;
    st=-INF;
    ed=INF;
 
    visit[from]=1;
    for(i=0;i<V[from].size();i++){
        to=V[from][i];
        if(visit[to]==1)
            continue;
        dfs(to);
//printf("%d %d %d\n",from,to,s[to].num);
        if(s[to].rig!=INF){
 
            if(ed!=INF && (st-s[to].rig)%2==0){ ///홀짝성에 어긋 난다면
                printf("No");
                exit(1);
            }
            if((ed<s[to].lef-1 || s[to].rig+1<st)){ ///겹치지 않는 다면
                printf("No");
                exit(1);
            }
         ///   범위의 교집합 구한다.
            st=max(st,s[to].lef-1);
            ed=min(ed,s[to].rig+1);
        }
    }
    if(s[from].num!=INF){
        if(st<=s[from].num && s[from].num<=ed){
            s[from].lef=s[from].num;
            s[from].rig=s[from].num;
        }
        else{
            printf("No");
            exit(1);
        }
    }
    else{
        s[from].lef=st;
        s[from].rig=ed;
    }
 
   // printf("%d %d //%d %d//st:%d,ed:%d\n",from,s[from].num,s[from].lef,s[from].rig,st,ed);
}
void dfs2(int from,int num)
{
    int i,to;
    visit2[from]=1;
   // printf("%d %d %d\n",from,s[from].num,num);
    if(s[from].lef<=num-1 && num-1<=s[from].rig){
        s[from].num=num-1;
    }
    else
        s[from].num=num+1;
    for(i=0;i<V[from].size();i++){
        to=V[from][i];
      //  printf("->%d %d\n",from,to);
        if(visit2[to]==0){
            dfs2(to,s[from].num);
        }
    }
}
int main()
{
  //  freopen("input.txt","r",stdin);
    scanf("%d",&n);
    int i,v,p;
    for(i=1;i<n;i++){
        scanf("%d%d",&ai[i],&bi[i]);
        s[i].lef=-INF;
        s[i].rig=s[i].num=INF;
        V[ai[i]].push_back(bi[i]);
        V[bi[i]].push_back(ai[i]);
    }
    s[n].lef=-INF;
    s[n].rig=s[n].num=INF;
    scanf("%d",&m);
    for(i=1;i<=m;i++){
        scanf("%d%d",&v,&p);
        s[v].lef=p;
        s[v].rig=p;
        s[v].num=p;
    }
    dfs(1);
  //  dfs2(1,s[1].rig==INF ? 0: s[1].rig+1);
    printf("Yes\n");
    for(i=1;i<=n;i++)
        printf("%d\n",s[i].num);

Compiler output:
a.cc: In function 'void dfs(int)':
a.cc:17:5: error: reference to 'visit' is ambiguous
   17 |     visit[from]=1;
      |     ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:80,
                 from a.cc:1:
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:10:21: note:                 'int visit [100005]'
   10 | int n,m,ai[N],bi[N],visit[N],visit2[N];
      |                     ^~~~~
a.cc:20:12: error: reference to 'visit' is ambiguous
   20 |         if(visit[to]==1)
      |            ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:10:21: note:                 'int visit [100005]'
   10 | int n,m,ai[N],bi[N],visit[N],visit2[N];
      |                     ^~~~~
a.cc: In function 'int main()':
a.cc:99:33: error: expected '}' at end of input
   99 |         printf("%d\n",s[i].num);
      |                                 ^
a.cc:75:1: note: to match this '{'
   75 | {
      | ^