criyle/codenet-compile-errors huggingface dataset:
Language: C++

#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define pb push_back
typedef pair<int, int> ii;
typedef long long ll;

const int maxn = 1e5+5;

vector<int> adj[maxn];
int has[maxn];

bool flex[maxn];
int pari[maxn];

int lb[maxn], rb[maxn];

int ans[maxn];

int n, k;

bool solve(int u, int p)
{
	// printf("solving %d\n", u);
	for(int v : adj[u])
	{
		if(v == p) continue;
		if(!solve(v, u)) return false;
	}
	lb[u] = -1e9, rb[u] = 1e9;
	bool allflex = true;
	pari[u] = -1;
	for(int v : adj[u])
	{
		if(v == p) continue;
		if(flex[v]) continue;
		allflex = false;
		if(pari[v] != -1 && pari[u] == -1)
		{
			pari[u] = 1-pari[v];
		}
		else if(pari[v] != -1 && pari[u] == pari[v])  return false;
		lb[u] = max(lb[u], lb[v]-1);
		rb[u] = min(rb[u], rb[v]+1);
	}
	// printf("fin %d: [%d, %d] (%d)\n", u, lb[u], rb[u], pari[u]);
	if(lb[u]> rb[u]) return false;
	if(has[u] != -1)
	{
		if(!(lb[u]<= has[u] && has[u]<= rb[u])) return false;
		if(pari[u] != -1 && has[u]%2 != pari[u]) return false;
		lb[u] = rb[u] = has[u];
		return true;
	}
	if(allflex) flex[u] = true;
	return true;
}

void recon(int u, int p)
{
	if(p)
	{
		if(lb[u]<= ans[p]-1 && ans[p]-1<= rb[u]) ans[u] = ans[p]-1;
		else if(lb[u]<= ans[p]+1 && ans[p]+1<= rb[u]) ans[u] = ans[p]+1;
		else assert(false);
	}
	for(int v : adj[u])
	{
		if(v == p) continue;
		recon(v, u);
	}
}

int main()
{
	scanf("%d", &n);
	for(int i = 1; i<= n-1; i++)
	{
		int u, v; scanf("%d %d", &u, &v);
		adj[u].pb(v); adj[v].pb(u);
	}
	for(int i = 1; i<= n; i++) has[u] = -1;
	scanf("%d", &k);
	for(int i = 1; i<= k; i++)
	{
		int v, p; scanf("%d %d", &v, &p);
		has[v] = p;
	}
	if(!solve(1, 0))
	{
		puts("No"); return 0;
	}
	ans[1] = lb[1];
	recon(1, 0);
	puts("Yes");
	for(int i = 1; i<= n; i++) printf("%d\n", ans[i]);
}

Compiler output:
a.cc: In function 'int main()':
a.cc:83:40: error: 'u' was not declared in this scope
   83 |         for(int i = 1; i<= n; i++) has[u] = -1;
      |                                        ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define pb push_back
typedef pair<int, int> ii;
typedef long long ll;

const int maxn = 1e5+5;

vector<int> adj[maxn];
int has[maxn];

bool flex[maxn];
int pari[maxn];

int lb[maxn], rb[maxn];

int ans[maxn];

int n, k;

bool solve(int u, int p)
{
	// printf("solving %d\n", u);
	for(int v : adj[u])
	{
		if(v == p) continue;
		if(!solve(v, u)) return false;
	}
	lb[u] = -1e9, rb[u] = 1e9;
	bool allflex = true;
	pari[u] = -1;
	for(int v : adj[u])
	{
		if(v == p) continue;
		if(flex(v)) continue;
		allflex = false;
		if(pari[v] != -1 && pari[u] == -1)
		{
			pari[u] = 1-pari[v];
		}
		else if(pari[v] != -1 && pari[u] == pari[v])  return false;
		lb[u] = max(lb[u], lb[v]-1);
		rb[u] = min(rb[u], rb[v]+1);
	}
	// printf("fin %d: [%d, %d] (%d)\n", u, lb[u], rb[u], pari[u]);
	if(lb[u]> rb[u]) return false;
	if(has[u])
	{
		if(!(lb[u]<= has[u] && has[u]<= rb[u])) return false;
		if(pari[u] != -1 && has[u]%2 != pari[u]) return false;
		lb[u] = rb[u] = has[u];
		return true;
	}
	if(allflex) flex[u] = true;
	return true;
}

void recon(int u, int p)
{
	if(p)
	{
		if(lb[u]<= ans[p]-1 && ans[p]-1<= rb[u]) ans[u] = ans[p]-1;
		else if(lb[u]<= ans[p]+1 && ans[p]+1<= rb[u]) ans[u] = ans[p]+1;
		else assert(false);
	}
	for(int v : adj[u])
	{
		if(v == p) continue;
		recon(v, u);
	}
}

int main()
{
	scanf("%d", &n);
	for(int i = 1; i<= n-1; i++)
	{
		int u, v; scanf("%d %d", &u, &v);
		adj[u].pb(v); adj[v].pb(u);
	}
	scanf("%d", &k);
	for(int i = 1; i<= k; i++)
	{
		int v, p; scanf("%d %d", &v, &p);
		has[v] = p;
	}
	if(!solve(1, 0))
	{
		puts("No"); return 0;
	}
	ans[1] = lb[1];
	recon(1, 0);
	puts("Yes");
	for(int i = 1; i<= n; i++) printf("%d\n", ans[i]);
}

Compiler output:
a.cc: In function 'bool solve(int, int)':
a.cc:37:24: error: 'flex' cannot be used as a function
   37 |                 if(flex(v)) continue;
      |                    ~~~~^~~
Language: C++

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(W,n)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {REP(aaa,i){REP(bbb,j)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;

vector<vector<int>> v(111111);
ll mpL[111111];
ll mpR[111111];
bool visited[111111]

void dfs(int node, int pre,ll LL, ll RR){
	//cout << node << " " << LL << " " << RR << endl;
	if(visited[node] && node != pre && mpL[node] >= LL && mpR[node] <= RR)return;
	visited[node] = true;
	mpL[node] = max(mpL[node], LL);
	mpR[node] = min(mpR[node], RR);
	if(mpL[node] > mpR[node])return;

	REP(i,v[node].size()){
		if(v[node][i] == pre)continue;
		dfs(v[node][i], node, mpL[node] - 1, mpR[node] + 1);
	}
}

int main(){

	int n;cin >> n;
	REP(i,n-1){
		int a,b;cin >> a >> b;
		a--;b--;
		v[a].PB(b);
		v[b].PB(a);
	}
	REP(i,111111){
		mpL[i] = -LLINF;
		mpR[i] = LLINF;
	}
	int k;cin >> k;
	vector<P> que;
	REP(i,k){
		ll a,b;cin >> a >> b;a--;
		que.EB(a,b);
		mpL[a] = b;
		mpR[a] = b;
	}

	REP(i,k)dfs(que[i].FI, que[i].FI, que[i].SE, que[i].SE);

	bool flag = true;
	REP(i,n)if(mpL[i] > mpR[i])flag = false;
	if(!flag){
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
		REP(i,n)cout << mpR[i] << endl;
	}

	return 0;
}


Compiler output:
a.cc:28:1: error: expected initializer before 'void'
   28 | void dfs(int node, int pre,ll LL, ll RR){
      | ^~~~
a.cc: In function 'int main()':
a.cc:64:17: error: 'dfs' was not declared in this scope; did you mean 'ffs'?
   64 |         REP(i,k)dfs(que[i].FI, que[i].FI, que[i].SE, que[i].SE);
      |                 ^~~
      |                 ffs
Language: C++

#include <iostream>
#include <fstream>
#include <cstdio>
#include <cassert>
#include <complex>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <sstream>
#include <ctime>
#include <cctype>
#include <set>
#include <map>
#include <queue>
#include <bitset>
#include <deque>
#include <stack>
#include <memory.h>
using namespace std;
typedef long long ll;
#define mp make_pair
vector<int> nei[100100];
priority_queue <pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > pq;
int num[100005],ans=0;;
bool dfs(int now, int par){
	for(int i=0;i<nei[now].size();i++){
		cout<<nei[now][i]<<endl;
		if(nei[now][i]==par){
			continue;
		}
		if(abs(num[nei[now]]-num[nei[now][i])!=1){
			return false;
		}
		if(!dfs(nei[now][i],now)){
			return false;
		}
	}
	return true;
}
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n-1;i++){
		int a,b;
		cin>>a>>b;
		a--,b--;
		nei[a].push_back(b);
		nei[b].push_back(a);
	}
	int m;
	cin>>m;
	memset(num,-1,sizeof(num));
	for(int i=0;i<m;i++){
		int a,val;
		cin>>a>>val;
		a--;
		num[a]=val;
		pq.push(mp(val,a));
	}
	while(!pq.empty()){
		pair<int,int> p=pq.top();
		pq.pop();
		int v=p.second;
		for(int i=0;i<nei[i].size();i++){
			if(num[nei[v][i]]==-1){
				num[nei[v][i]]=num[v]+1;
				pq.push(mp(num[nei[v][i]],nei[v][i]));
			}
		}
	}
	if(!dfs(0,-1)){
		cout<<"No";
	}
	else{
		cout<<"Yes"<<endl;
		for(int i=0;i<n;i++){
			cout<<num[i]<<endl;
		}
	}
	return 0;
}

Compiler output:
a.cc: In function 'bool dfs(int, int)':
a.cc:36:27: error: no match for 'operator[]' (operand types are 'int [100005]' and 'std::vector<int>')
   36 |                 if(abs(num[nei[now]]-num[nei[now][i])!=1){
      |                           ^
a.cc:36:53: error: expected ']' before ')' token
   36 |                 if(abs(num[nei[now]]-num[nei[now][i])!=1){
      |                                                     ^
      |                                                     ]
Language: C++

#include <iostream>
#include <fstream>
#include <cstdio>
#include <cassert>
#include <complex>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <sstream>
#include <ctime>
#include <cctype>
#include <set>
#include <map>
#include <queue>
#include <bitset>
#include <deque>
#include <stack>
#include <memory.h>
using namespace std;
typedef long long ll;
#define mp make_pair
vector<int> a[100100];
priority_queue <pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > pq;
int tag[100100],ans=0;;
bool dfs(int now, int par){
	for(int i=0;i<a[i].size();i++){
		if(a[now][i]==par){
			continue;
		}
		if(abs(tag[(-tag[a[now][i]])])!=1){
			return false;
		}
		if(!dfs(a[now][i],now)){
			return false;
		}
	}
	return true;
}
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n-1;i++){
		int v,g;
		cin>>v>>g;
		v--,g--;
		a[v].push_back(g);
		a[g].push_back(v);
	}
	int m;
	cin>>m;
	memset(tag,-1,sizeof(tag));
	for(int i=0;i<m;i++){
		int v,g;
		cin>>v>>g;
		v--;
		tag[v]=g;
		pq.push(mp(g,v));
	}
	while(!pq.empty()){
		pair<int,int> p=pq.top();
		pq.pop();
		int v=p.second;
		for(int i=0;i<a[i].size();i++){ 
			if(tag[a[v][i]]==-1){
				tag[a[v][i]]=tag[v]+1;
				pq.push(mp(tag[a[v][i]],a[v][i]));
			}
		}
	}
	if(!dfs(0,-1)){
		cout<<"No";
	}
	else{
		cout<<"Yes"<<endl;
		for(int i=0;i<n;i++){
			cout<<tag[i]<<endl;
		}
	}
	return 0


Compiler output:
a.cc: In function 'int main()':
a.cc:84:17: error: expected ';' at end of input
   84 |         return 0
      |                 ^
      |                 ;
a.cc:84:17: error: expected '}' at end of input
a.cc:44:11: note: to match this '{'
   44 | int main(){
      |           ^
Language: C++

#include <iostream>
#include <fstream>
#include <cstdio>
#include <cassert>
#include <complex>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <sstream>
#include <ctime>
#include <cctype>
#include <set>
#include <map>
#include <queue>
#include <bitset>
#include <deque>
#include <stack>
#include <memory.h>
using namespace std;
typedef long long ll;
#define mp make_pair
vector<int> a[100100];
priority_queue<pair<int, int>,vector<pair<int, int> >,greater<pair<int, int> > > pq;
int tag[100100];
bool dfs(int now, int par){
	for(int i=0;i<a.size();i++){
		if(a[now][i] == par) continue;
		if(abs(tag[-tag[a[now][i]]) != 1){
			return false;
		}
		if(!dfs(a[now][i], now)){
			return false;
		}
	}
	return true;
}
int main(){
	int n;
	cin >> n;
	for(int i=0;i<n-1;i++){
		int v, g;
		cin>>v>>g;
		v--, g--;
		a[v].push_back(g);
		a[g].push_back(v);
	}
	int m;
	cin>>m;
	memset(tag,-1,sizeof(tag));
	for(int i=0;i<m;i++){
		int v,g;
		cin>>v>>g;
		v--;
		tag[v]=g;
		pq.push(mp(g,v));
	}
	while(!pq.empty()){
		pair<int, int> p = pq.top();
		pq.pop();
		int v=p.second;
		for(int i=0;i<a.size();i++){ 
			if(tag[a[v][i]] == -1){
				tag[a[v][i]] = tag[v]+1;
				pq.push(mp(tag[a[v][i]],a[v][i]));
			}
		}
	}
	if(!dfs(0, -1)){
		cout<<"No";
	}
	else{
		cout<<"Yes"<<endl;
		for(int i=0;i<n;i++){
			cout<<tag[i]<<endl;
		}
	}
	return 0;
}


Compiler output:
a.cc: In function 'bool dfs(int, int)':
a.cc:31:25: error: request for member 'size' in 'a', which is of non-class type 'std::vector<int> [100100]'
   31 |         for(int i=0;i<a.size();i++){
      |                         ^~~~
a.cc:33:43: error: expected ']' before ')' token
   33 |                 if(abs(tag[-tag[a[now][i]]) != 1){
      |                                           ^
      |                                           ]
a.cc: In function 'int main()':
a.cc:66:33: error: request for member 'size' in 'a', which is of non-class type 'std::vector<int> [100100]'
   66 |                 for(int i=0;i<a.size();i++){
      |                                 ^~~~
Language: C++

#include <cstdio>
#include <queue>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
 
const int SIZE=100005;
const int INF=100000005;
 
vector<int> mp[SIZE];
int id[SIZE],L[SIZE],R[SIZE];
bool ok=true;
 
void solve(int v,int p){
    if(id[v]==-1){
        L[v]=-INF;
        R[v]=INF;
    }
    else{
        L[v]=R[v]=id[v];
    }
    for(int i=0;i<mp[v].size();i++){
        int to=mp[v][i];
        if(to==p) continue;
        solve(to,v);
        if(L[to]<-INF/2) continue;
        if(!(L[v]<-INF/2)){
            if(L[to]%2==L[v]%2){
                ok=false;
                return;
            }
        }
        L[v]=max(L[to]-1,L[v]);
        R[v]=min(R[to]+1,R[v]);
        if(L[v]>R[v]){
            ok=false;
            return;
        }
    }
}
 
void make(int v,int p){
    for(int i=0;i<mp[v].size();i++){
        int to=mp[v][i];
        if(to==p) continue;
        if(id[to]==-1){
            if(L[to]<=id[v]+1 && id[v]+1<=R[to]){
            	id[to]=id[v]+1; else id[to]=id[v]-1;
			}
        }
        make(to,v);
    }
}
 
int main(){
    int n,k;
    scanf("%d",&n);
    for(int i=0;i<n-1;i++){
        int a,b;
        scanf("%d%d",&a,&b);
        a--;
        b--;
        mp[a].push_back(b);
        mp[b].push_back(a);
        id[i]=-1;
    }
    id[n-1]=-1;
    scanf("%d",&k);
    for(int i=0;i<k;i++){
        int v,p;
        scanf("%d%d",&v,&p);
        v--;
        id[v]=p;
    }
    solve(0,-1);
    if(!ok) puts("No");
    else{
        puts("Yes");
        id[0]=L[0];
        make(0,-1);
        for(int i=0;i<n;i++){
        	printf("%d\n",id[i]);
		}
    }
    return 0;
}

Compiler output:
a.cc: In function 'void make(int, int)':
a.cc:49:33: error: expected '}' before 'else'
   49 |                 id[to]=id[v]+1; else id[to]=id[v]-1;
      |                                 ^~~~
a.cc:48:49: note: to match this '{'
   48 |             if(L[to]<=id[v]+1 && id[v]+1<=R[to]){
      |                                                 ^
a.cc:52:14: error: 'to' was not declared in this scope; did you mean 'tm'?
   52 |         make(to,v);
      |              ^~
      |              tm
a.cc: At global scope:
a.cc:54:1: error: expected declaration before '}' token
   54 | }
      | ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > >q;
int ans[100003];
vector<int>v[100003];
int main(){
	memset(ans,-1,sizeof(ans));
	int n,a,b,k;
	cin>>n;
	for(int i=1;i<n;i++)
	{
		cin>>a>>b;
		a--;b--;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	cin>>k;
	for(int i=0;i<k;i++)
	{
		int p,x;
		cin>>p>>x;
		p--;
		ans[p]=x;
		q.push(make_pair(p,x));
	}
	while(!q.empty()){
		pair<int,int>tmp=q.top();
		tmp.first=-tmp.first;
		q.pop();
		for(int i=0;i<tmp.second.size();i++)
			if(ans[tmp.second[i]]==-1)
			{
				ans[tmp.second[i]]=ans[tmp.first]+1;
				q.push(make_pair(-tmp.second[i],v[tmp.second[i]]));
			}
	}
	for(int i=0;i<n;i++)
		for(int j=0;j<v[i].size();j++)
			if(fabs(ans[i]-ans[v[i][j]])!=1)
			{
				cout<<"No";
				return 0;
			}
	cout<<"Yes"<<endl;
	for(int i=0;i<n;i++)
		cout<<ans[i]<<endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:30:42: error: request for member 'size' in 'tmp.std::pair<int, int>::second', which is of non-class type 'int'
   30 |                 for(int i=0;i<tmp.second.size();i++)
      |                                          ^~~~
a.cc:31:42: error: invalid types 'int[int]' for array subscript
   31 |                         if(ans[tmp.second[i]]==-1)
      |                                          ^
a.cc:33:47: error: invalid types 'int[int]' for array subscript
   33 |                                 ans[tmp.second[i]]=ans[tmp.first]+1;
      |                                               ^
a.cc:34:61: error: invalid types 'int[int]' for array subscript
   34 |                                 q.push(make_pair(-tmp.second[i],v[tmp.second[i]]));
      |                                                             ^
a.cc:34:77: error: invalid types 'int[int]' for array subscript
   34 |                                 q.push(make_pair(-tmp.second[i],v[tmp.second[i]]));
      |                                                                             ^
Language: C++

#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<math.h>
#include<numeric>
#include<cassert>
#include<random>
#include<deque>
#include<chrono>
#include<unordered_map>
#include<list>
#include<fstream>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
const ll E=1e18+7;
#define F first
#define S second
#define MK make_pair
const ll MOD=1000000007;

ll n;
vector<pll> v;
vector<vector<ll>> e;
vector<pll> D;
vector<pair<bool,ll>> de;

pair<bool,pll> dfs(ll where,ll parent,pll lmt,bool F){
    if(de[where].F){
        if(de[where].S%2!=F?1:0){return {false,{0,0}};}
        if(lmt.F<de[where].S || lmt.S>de[where].S){return {false,{0,0}};}
        lmt={de[where].S,de[where].S};
    }
    for(int i=0;i<e[where].size();i++){
        ll to=e[where][i];
        if(to==parent){continue;}
        pair<bool,pll> ret=dfs(to,where,{lmt.F+1,lmt.S-1},!F);
        lmt.F=min(lmt.F,ret.S.F);
        lmt.S=max(lmt.S,ret.S.S);
        if(lmt.F<lmt.S || !ret.F){return {false,{0,0}};}
    }
    v[where].F=lmt.F; v[where].S=lmt.S;
    lmt.F++; lmt.S--;
    return {true,lmt};
}

vector<int> color;

void dfsC(ll where){
    for(int i=0;i<e[where].size();i++){
        ll to=e[where][i];
        if(color[to]==-1){
            color[to]=color[where]==1?0:1;
            dfsC(to);
        }
    }
}




int main(){
    cin>>n;
    e.resize(n);
    v.resize(n);
    de.resize(n,{false,-1});
    color.resize(n,-1);
    for(int i=0;i<n-1;i++){
        ll u,v;
        cin>>u>>v; u--; v--;
        e[u].push_back(v);
        e[v].push_back(u);
    }
    ll k;
    cin>>k;
    D.resize(k);
    for(int i=0;i<k;i++){
        cin>>D[i].F>>D[i].S;
        --D[i].F;
        de[D[i].F]={true,D[i].S};
    }
    if(k==0){cout<<"Yes"<<endl; return 0;}
    color[D[0].F]=D[0].S%2;
    dfsC(D[0].F);
    for(int i=0;i<k;i++){
        if(color[D[i].F]!=D[i].S%2){cout<<"No"<<endl; return 0}
    }
    if(!dfs(D[0].F,-1,{D[0].S,D[0].S},D[0].S%2).F){cout<<"No"<<endl; return 0;}
    cout<<"Yes"<<endl;
    for(int i=0;i<n;i++){
        cout<<v[i].F<<endl;
    }
    
    
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:99:63: error: expected ';' before '}' token
   99 |         if(color[D[i].F]!=D[i].S%2){cout<<"No"<<endl; return 0}
      |                                                               ^
      |                                                               ;
Language: C++

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

void Read(int &p)
{
	p=0;
	char c=getchar();
	while(c<'0'||c>'9') c=getchar();
	while(c>='0'&&c<='9')
		p=p*10+c-'0',c=getchar();
}

const int MAXN=102018;
int N,k,root,u,v,val[MAXN],eoro[MAXN];
bool vis[MAXN],ol[MAXN];
vector<int> G[MAXN];
vector<int> C[MAXN];

bool build_tree(int p)
{
	vis[p]=1;
	for(unsigned int i=0;i<G[p].size();i++)
	{
		int t=G[p][i];
		if(!vis[t])
		{
			C[p].push_back(t);
			if(eoro[t]!=-1 && eoro[t]==eoro[p]) return 1;
			eoro[t]=(eoro[p]+1)%2;
			bool o=build_tree(t);
			if(o) return 1;
		}
	}
	return 0;
}


bool ed;
void draw(int p)
{
	if(ed) return;
	if(C[p].size()==0)
	{
		bool cnt=0;
		for(int i=1;i<=N && !cnt;i++)
			if(val[i]==-1) cnt=1;
		
		if(!cnt)
		{
			for(int i=1;i<=N;i++)
				printf("%d\n",val[i]);
			ed=1;
		}
		return ;
	}
	for(unsigned int i=0;i<C[p].size() && !ed;i++)
	{
		int t=C[p][i];
		if(ol[t]) 
		{ 
			if(val[t]-val[p]>1 || val[p]-val[t]>1)
			{
				if(ol[p]) ed=1,puts("No");
				return ;
			}
			else draw(t);
			continue;
		}
		val[t]=val[p]+1,draw(t),
		if(val[t]>=1) val[t]=val[p]-1,draw(t);
	}
	if(ed) return ;
}

int main()
{
	memset(eoro,-1,sizeof eoro);
	memset(val,-1,sizeof val);
	Read(N);
	for(int i=2;i<=N;i++)
		Read(u),Read(v),G[u].push_back(v),G[v].push_back(u);
	
	Read(k);
	Read(root),Read(val[root]),eoro[root]=val[root]%2,ol[root]=1;
	for(int i=2;i<=k;i++)
		Read(u),Read(v),val[u]=v,eoro[u]=v%2,ol[u]=1;
	
	if(build_tree(root)) ed=1,puts("No");
	else draw(root);
	if(!ed) puts("No");
}

Compiler output:
a.cc: In function 'void draw(int)':
a.cc:74:17: error: expected primary-expression before 'if'
   74 |                 if(val[t]>=1) val[t]=val[p]-1,draw(t);
      |                 ^~
Language: C++

#include <vector>
#include <cstdlib>
#include <utility>
#include <algorithm>

const int N = 1e5 + 10, INF = 1e7;
int n, rt, f[N], p[N], k;
std::vector<int> to[N], c[N];
std::pair<int, int> r[N];
bool o1, o2, d[N], h[N];

std::pair<int, int> merge(std::pair<int, int> a, std::pair<int, int> b) {
    return std::make_pair(std::max(a.first, b.first), std::min(a.second, b.second));
}

void build(int cur) {
    for (int i : to[cur])
        if (i != f[cur]) {
            c[cur].push_back(i);
            f[i] = cur;
            d[i] = !d[cur];
            build(i);
        }
}

void dfs(int cur) {
    if (cur != rt)
        r[cur] = merge(r[cur], std::make_pair(r[f[cur]].first - 1, r[f[cur]].second + 1));
    for (int i : c[cur]) {
        dfs(i);
        r[cur] = merge(r[cur], std::make_pair(r[i].first - 1, r[i].second + 1));
    }
}

void query(int cur) {
    p[cur] = r[cur].first;
    if (cur != rt && p[cur] == p[f[cur]])
        p[cur]++;
    for (int i : c[cur]) {
        r[i] = merge(r[i], std::make_pair(p[cur] - 1, p[cur] + 1));
        query(i);
    }
}

int main() {
    scanf("%d", &n);
    rt = rand() % 100000000 + 1;
rt = rt % n + 1;
    for (int i = 1; i < n; i++) {
        static int t1, t2;
        scanf("%d%d", &t1, &t2);
        to[t1].push_back(t2);
        to[t2].push_back(t1);
    }
    build(rt);
    for (int i = 1; i <= n; i++)
        r[i] = std::make_pair(-INF, INF);
    scanf("%d", &k);
    for (int i = 1; i <= k; i++) {
        static int t1, t2;
        scanf("%d%d", &t1, &t2);
        h[t1] = true;
        p[t1] = t2;
        r[t1] = std::make_pair(t2, t2);
        ((d[t1] ^ (t2 & 1)) ? o1 : o2) = true;
    }
    if (o1 && o2) {
        puts("No");
        return 0;
    }

    dfs(rt);
    if (r[rt].first <= r[rt].second) {
        puts("Yes");
        query(rt);
        for (int i = 1; i <= n; i++)
            printf("%d\n", p[i]);
    } else {
        puts("No");
    }
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:46:5: error: 'scanf' was not declared in this scope
   46 |     scanf("%d", &n);
      |     ^~~~~
a.cc:68:9: error: 'puts' was not declared in this scope
   68 |         puts("No");
      |         ^~~~
a.cc:74:9: error: 'puts' was not declared in this scope
   74 |         puts("Yes");
      |         ^~~~
a.cc:77:13: error: 'printf' was not declared in this scope
   77 |             printf("%d\n", p[i]);
      |             ^~~~~~
a.cc:5:1: note: 'printf' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
    4 | #include <algorithm>
  +++ |+#include <cstdio>
    5 | 
a.cc:79:9: error: 'puts' was not declared in this scope
   79 |         puts("No");
      |         ^~~~
Language: C++

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
#define ll long long
#define inf 1e9
#define eps 1e-10
#define mod 9901
#define mkp make_pair
using namespace std;
int i,j,k,m,s,t,n,ans1,ans2,n1,nn,m1,mx;
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*10+ch-'0';ch=getchar();}
	return x*f;
}
int kabs(int a)
{
   if (a<0) return -a;
   return a; 
}
void add(int &x,int y)
{
   x+=y;
   if (x>=mod) x-=mod;
}
void dec(int &x,int y)
{
	x-=y;
	if (x<0) x+=mod;
}
int bo,first[101000],net[201000],zhi[201000],a[101000],p[101000],l1[101000],r1[101000];
void insert(int u,int v)
{
	net[++m1]=first[u];
	first[u]=m1;
	zhi[m1]=v;
}
void dfs(int x,int fa)
{
	if (!bo) return;
	int k,v,bo2=0;
	for (k=first[x];k;k=net[k])
	{
		v=zhi[k];
		if (v==fa) continue;
		dfs(v,x);
		p[x]|=p[v];
	}
	if (a[x]!=-1) p[x]=1;
	if (!bo) return;
	if (!p[x]) return;
	if (a[x]!=-1)
		bo2=1,l1[x]=r1[x]=a[x];
	for (k=first[x];k;k=net[k])
	{
		v=zhi[k];
		if (v==fa) continue;
		if (!p[v]) continue;
		if (!bo2)
		{
			bo2=1;
			l1[x]=l1[v]-1;
			r1[x]=r1[v]+1;
		} else
		{
			if (l1[v]-1>r) {bo=0;return;}
			if (r1[v]+1<l) {bo=0;return;}
			if (l1[x]%2!=(l1[v]-1)%2) {bo=0;return;}
			l1[x]=max(l1[x],l1[v]-1);
			r1[x]=min(r1[x],r1[v]+1);
			if (l1[x]>r1[x]) {bo=0;return;}
		}
	}
}
void solve(int x,int fa)
{
	int k,v;
	if (x==1) a[x]=l1[x]; else
	if (!p[x]||(a[fa]+1>=l1[x]&&a[fa]+1<=r1[x])) a[x]=a[fa]+1; else a[x]=a[fa]-1;
	for (k=first[x];k;k=net[k])
	{
		v=zhi[k];
		if (v==fa) continue;
		solve(v,x);
	}
}
int main()
{
	scanf("%d",&n);
	for (i=1;i<n;i++)
		scanf("%d%d",&s,&t),insert(s,t),insert(t,s);
	scanf("%d",&m);
	memset(a,-1,sizeof(a));
	for (i=1;i<=m;i++)
		scanf("%d%d",&s,&t),a[s]=t,p[s]=1;
	bo=1;
	dfs(1,0);
	if (!bo)
	{
		puts("NO");
		return 0;
	}
	solve(1,0);
	puts("YES");
	for (i=1;i<=n;i++)
		printf("%d\n",a[i]);
}

Compiler output:
a.cc: In function 'void dfs(int, int)':
a.cc:75:37: error: 'r' was not declared in this scope
   75 |                         if (l1[v]-1>r) {bo=0;return;}
      |                                     ^
a.cc:76:37: error: 'l' was not declared in this scope
   76 |                         if (r1[v]+1<l) {bo=0;return;}
      |                                     ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
#define N 1111116
#define inf 1111111116

int n,x[N],y[N],p[N],next[N],f[N];
priority_queue<pair<int,int> > q;

int read(){
	int x=0,f=1;char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-')  f=-f;
	for (;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return x*f;
}

int main(){
	n=read();
	for (int i=1;i<=n-1;i++){
		x[2*i-1]=y[2*i]=read();
		y[2*i-1]=x[2*i]=read();
		next[2*i-1]=p[x[2*i-1]];p[x[2*i-1]]=2*i-1;
		next[2*i]=p[x[2*i]];p[x[2*i]]=2*i;
	}
	fill(f+1,f+n+1,-inf);
	for (int k=read();k;k--){
		int x=read(),y=read();
		f[x]=y;q.push(make_pair(y,x));
	}
	while (!q.empty()){
		int t=p[q.top().second];q.pop();
		for (;t;t=next[t])
			if (f[y[t]]==-inf){
				f[y[t]]=f[x[t]]-1;
				q.push(make_pair(f[y[t]],y[t]));
			}
	}
	for (int i=1;i<=2*n-2;i++)
		if (abs(f[x[i]]-f[y[i]])!=1){
			printf("No\n");return 0;
		}
	printf("Yes\n");
	for (int i=1;i<=n;i++)
		printf("%d\n",f[i]);
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:21:17: error: reference to 'next' is ambiguous
   21 |                 next[2*i-1]=p[x[2*i-1]];p[x[2*i-1]]=2*i-1;
      |                 ^~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:66,
                 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_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:6:22: note:                 'int next [1111116]'
    6 | int n,x[N],y[N],p[N],next[N],f[N];
      |                      ^~~~
a.cc:22:17: error: reference to 'next' is ambiguous
   22 |                 next[2*i]=p[x[2*i]];p[x[2*i]]=2*i;
      |                 ^~~~
/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:6:22: note:                 'int next [1111116]'
    6 | int n,x[N],y[N],p[N],next[N],f[N];
      |                      ^~~~
a.cc:31:27: error: reference to 'next' is ambiguous
   31 |                 for (;t;t=next[t])
      |                           ^~~~
/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:6:22: note:                 'int next [1111116]'
    6 | int n,x[N],y[N],p[N],next[N],f[N];
      |                      ^~~~
Language: C++

#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <utility>
 
typedef long long ll;
typedef std::pair<int, int> pii;
 
#define mp std::make_pair
 
int n, k, ans[100005];
bool vis[100005];
int head[100005], next[100005 << 1], to[100005 << 1], ed = 0;
int deg[100005];
 
void AddEdge(int u, int v) {
	next[++ed] = head[u]; head[u] = ed; to[ed] = v;
}
 
pii dp[100005];
 
pii DP(int now, int fa, bool odd, int L, int R) {
	if (vis[now]) {
		if (ans[now] < L || ans[now] > R || (ans[now] & 1) != odd) {
			puts("No"); exit(0);
		}
		L = R = ans[now];
	}
	pii tmp;
	for (int i = head[now]; i; i = next[i]) {
		if (to[i] == fa) continue;
		tmp = DP(to[i], now, odd ^ 1, L - 1, R + 1);
		L = std::max(L, tmp.first - 1);
		R = std::min(R, tmp.second + 1);
		if (L > R) {
			puts("No"); exit(0);
		}
	}
	return dp[now] = mp(L, R);
}
 
void DFS(int now, int fa, bool odd) {
	ans[now] = dp[now].first + (dp[now].first & 1 != odd);
	for (int i = head[now]; i; i = next[i]) {
		if (to[i] == fa) continue;
		DFS(to[i], now);
	}
}
 
int main() {
	scanf("%d", &n);
	for (int u, v, i = 1; i < n; ++i) {
		scanf("%d%d", &u, &v);
		AddEdge(u, v);
		AddEdge(v, u);
		++deg[u]; ++deg[v];
	}
	scanf("%d", &k);
	int v, p;
	for (int i = 1; i <= k; ++i) {
		scanf("%d%d", &v, &p);
		ans[v] = p;
		vis[v] = 1;
	}
 
	DP(v, 0, p & 1, p, p);
	DFS(v, 0, p & 1);
 
	puts("Yes");
	for (int i = 1; i <= n; ++i) printf("%d\n", ans[i]);
 
	return 0;
}

Compiler output:
a.cc: In function 'void DFS(int, int, bool)':
a.cc:46:20: error: too few arguments to function 'void DFS(int, int, bool)'
   46 |                 DFS(to[i], now);
      |                 ~~~^~~~~~~~~~~~
a.cc:42:6: note: declared here
   42 | void DFS(int now, int fa, bool odd) {
      |      ^~~
Language: C++

#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <utility>
 
typedef long long ll;
typedef std::pair<int, int> pii;
 
#define mp std::make_pair
 
int n, k, ans[100005];
bool vis[100005];
int head[100005], next[100005 << 1], to[100005 << 1], ed = 0;
int deg[100005];
 
void AddEdge(int u, int v) {
	next[++ed] = head[u]; head[u] = ed; to[ed] = v;
}
 
pii dp[100005];
 
pii DP(int now, int fa, bool odd, int L, int R) {
	if (vis[now]) {
		if (ans[now] < L || ans[now] > R || (ans[now] & 1) != odd) {
			puts("No"); exit(0);
		}
		L = R = ans[now];
	}
	pii tmp;
	for (int i = head[now]; i; i = next[i]) {
		if (to[i] == fa) continue;
		tmp = DP(to[i], now, odd ^ 1, L - 1, R + 1);
		L = std::max(L, tmp.first - 1);
		R = std::min(R, tmp.second + 1);
		if (L > R) {
			puts("No"); exit(0);
		}
	}
	return dp[now] = mp(L, R);
}
 
void DFS(int now, int fa) {
	ans[now] = dp[now].first;
	for (int i = head[now]; i; i = next[i]) {
		if (to[i] == fa) continue;
		DFS(to[i], now);
	}
}
 
int main() {
	scanf("%d", &n);
	for (int u, v, i = 1; i < n; ++i) {
		scanf("%d%d", &u, &v);
		AddEdge(u, v);
		AddEdge(v, u);
		++deg[u]; ++deg[v];
	}
	scanf("%d", &k);
	int v, p;
	for (int i = 1; i <= k; ++i) {
		scanf("%d%d", &v, &p);
		ans[v] = p;
		vis[v] = 1;
	}
 
	DP(v, 0, p & 1, p, p);
	DFS(v, 0, p, p);
 
	puts("Yes");
	for (int i = 1; i <= n; ++i) printf("%d\n", ans[i]);
 
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:67:12: error: too many arguments to function 'void DFS(int, int)'
   67 |         DFS(v, 0, p, p);
      |         ~~~^~~~~~~~~~~~
a.cc:42:6: note: declared here
   42 | void DFS(int now, int fa) {
      |      ^~~
Language: C++

#include<iostream>
#include<cstdio>
#include<vector>
#include<cstdlib>
#include<queue>
using namespace std;
int n,k;
int dist[100010];
bool vis[100010];
int ans[100010];
vector<pair<int,int> >v[100010];
void dij(int st)
{
	for(int i=1;i<=n;i++)dist[i]=1e9;
	priority_queue<pair<int,int> , vector<pair<int,int> > ,greater<pair<int,int> > >q;
	q.push(make_pair(0,0));
	memset(vis,false,sizeof(vis));
	int s=n+1;
	while(s--)
	{
		while(!q.empty() && (vis[q.top().second] || dist[q.top().second]!=q.top().first))q.pop();
		int x=q.top().second;
		q.pop();
		vis[x]=true;
		for(int i=0;i<v[x].size();i++)
		{
			int y=v[x][i].first,w=v[x][i].second;
			if(vis[y])continue;
			if(dist[x]+w<dist[y])
			{
				dist[y]=dist[x]+w;
				q.push(make_pair(dist[y],y));
			}
		}
	}
} 
int main()
{
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		v[x].push_back(make_pair(y,1));
		v[y].push_back(make_pair(x,1));
	}
	for(int i=1;i<=n;i++)ans[i]=-1;
	scanf("%d",&k);
	for(int i=1;i<=k;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		v[0].push_back(make_pair(x,y));
		ans[x]=y;
	}
	dij(0);
	for(int i=1;i<=n;i++)
	{
		if(ans[i]!=-1 && ans[i]!=dist[i])
		{
			printf("No");
			return 0;
		}
		ans[i]=dist[i];
	}
	puts("Yes");
	for(int i=1;i<=n;i++)
	{
		printf("%d\n",ans[i]);
	}
	return 0;
} 

Compiler output:
a.cc: In function 'void dij(int)':
a.cc:17:9: error: 'memset' was not declared in this scope
   17 |         memset(vis,false,sizeof(vis));
      |         ^~~~~~
a.cc:6:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    5 | #include<queue>
  +++ |+#include <cstring>
    6 | using namespace std;
Language: C++

// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> void get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'; t=getchar());
	if(t=='-')neg=true,t=getchar();
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) get1(a),get1(b)
#define get3(a,b,c) get1(a),get2(b,c)
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

vector<int> g[100111];
int n,k,a[100111],mn[100111],root;
bool add[100111];
void dfs(int x,int f=0,int d=0)
{
	mn[x]=inf;
	for(int i=0;i<(int)g[x].size();i++)
		if(g[x][i]!=f)
		{
			dfs(g[x][i],x,d+1);
			mn[x]=min(mn[x],mn[g[x][i]]);
		}
	if(a[x]&&(a[x]+d<a[root]||a[x]-d>a[root]||(a[root]-a[x]+d)%2==1))
	{
		puts("No");
		exit(0);
	}
	mn[x]=min(mn[x],(a[x]-a[root]+d)/2);
}
void dfs2(int x,int f=0,int v=0,int d=0)
{
	int val=a[root]-d+2*v;
	if(a[x]&&a[x]!=val)
	{
		puts("No");
		exit(0);
	}
	else a[x]=val;
	for(int i=0;i<(int)g[x].size();i++)
		if(g[x][i]!=f)
		{
			if(mn[g[x][i]]-v>0)add[g[x][i]]=1;
			dfs2(g[x][i],x,v+add[g[x][i]],d+1);
		}
}
int main()
{
	get1(n);
	for(int i=1,u,v;i<n;i++)
	{
		get2(u,v);
		g[u].pb(v);
		g[v].pb(u);
	}
	get1(k);
	for(int i=1,x,y;i<=k;i++)
	{
		get2(x,y);
		root=x;
		a[x]=y;
	}
	dfs(root);
	dfs2(root);
	puts("Yes");
	for(int i=1;i<=n;i++)printendl(a[i]);

Compiler output:
a.cc: In function 'int main()':
a.cc:105:46: error: expected '}' at end of input
  105 |         for(int i=1;i<=n;i++)printendl(a[i]);
      |                                              ^
a.cc:87:1: note: to match this '{'
   87 | {
      | ^
Language: C++

#include<bits/stdc++.h>
#define N 111111
#define M 222222
#define P 10001000
using namespace std;
int T,n,m,i,x,y,tot,S,fir[N],la[M],ne[M],V[N],L[N],R[N],AN[N];char s[N];bool ff,v[N];
void ins(int x,int y){la[++tot]=y;ne[tot]=fir[x];fir[x]=tot;}
void dfs1(int x,int fa){
	int lv=-1e9,rv=1e9;
	if(v[x])lv=rv=V[x];
	for(int i=fir[x];i;i=ne[i])if(la[i]!=fa){
		dfs1(la[i],x);
		lv=max(lv,L[la[i]]-1);
		rv=min(rv,R[la[i]]+1);
	}
	if(lv>rv)ff=1;
	if(!v[x])L[x]=lv,R[x]=rv;else{
		if(V[x]<lv||V[x]>rv)ff=1;
	}
}
void dfs2(int x,int fa){
	int lv=L[x],rv=R[x];
	if(fa)lv=max(lv,L[fa]-1),rv=min(rv,R[fa]+1);
	for(int i=fir[x];i;i=ne[i])if(la[i]!=fa){
		dfs2(la[i],x);
	}
	if(lv>rv)ff=1;
	if(!v[x])L[x]=lv,R[x]=rv;else{
		if(V[x]<lv||V[x]>rv)ff=1;
	}
}
int change(int x,int y){
	x--;
	int w=(y-x+1)/2;
	return x+w*2;
}
int gg(int x,int y){
	x++;
	int w=(x-y+1)/2;
	return x-w*2;
}
int to(int l1,int r1,int l2,int r2){
	if(l1-1<=l2)return change(l1,l2);
	if(r1+1>=r2)return gg(r1,r2);
}
void getans(int x,int fa){
	int o,i,lv,rv;
	if(v[x]){
		if(!fa||(AN[fa]-1==V[x]||AN[fa]+1==V[x]))AN[x]=V[x];else ff=1;
	}
	else{
		if(AN[fa]-1>=L[x]&&AN[fa]-1<=R[x])AN[x]=AN[fa]-1;
		else if(AN[fa]+1>=L[x]&&AN[fa]+1<=R[x])AN[x]=AN[fa]+1;
		else ff=1;
	}
	for(i=fir[x];i;i=ne[i])if(la[i]!=fa)getans(la[i],x,w^1);
}
void check(int x,int fa){
	if(fa)if(AN[fa]+1!=AN[x]&&AN[fa]-1!=AN[x])ff=1;
	for(int i=fir[x];i;i=ne[i])if(la[i]!=fa)check(la[i],x);
}
int main(){
	for(scanf("%d",&n),i=1;i<n;i++)scanf("%d%d",&x,&y),ins(x,y),ins(y,x);
	for(scanf("%d",&m),i=1;i<=m;i++)scanf("%d%d",&x,&y),v[x]=1,V[x]=y,S=x;
	if(!m)v[1]=1,V[1]=1,S=1;
	dfs1(1,0);dfs2(1,0);
	getans(S,0);
	if(ff)return puts("No"),0;
	check(S,0);
	if(ff)return puts("No"),0;
	puts("YES");
	for(i=1;i<=n;i++)printf("%d\n",AN[i]);
}

Compiler output:
a.cc: In function 'void getans(int, int)':
a.cc:56:60: error: 'w' was not declared in this scope
   56 |         for(i=fir[x];i;i=ne[i])if(la[i]!=fa)getans(la[i],x,w^1);
      |                                                            ^
a.cc: In function 'int to(int, int, int, int)':
a.cc:45:1: warning: control reaches end of non-void function [-Wreturn-type]
   45 | }
      | ^
Language: C++


#include <cstdio>
#include <iostream>
#include <cassert>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

int nNode;
int vs[100000+10];
int parity[100000+10];
int lbs[100000+10];
int ubs[100000+10];
vector<int> g[100000+10];

bool go(int u, int p) {
  REP(i, g[u].size()) {
    int v = g[u][i];
    if(v == p)
      continue;
    if(!go(v, u))
      return false;
  }
  if(lbs[u] > ubs[u] || parity[u] == 0) { // 無理
    return false;
  }
  if(lbs[u] == ubs[u] && (parity[u] & (1 << (lbs[u] % 2))) == 0) {
    return false;
  }
  if(p >= 0) {
    REP(i, 2) {
      if((parity[u] & (1 << i)) == 0) {
        parity[p] &= ~(1 << !i);
      }
    }
    lbs[p] = max(lbs[p], lbs[u]-1);
    ubs[p] = min(ubs[p], ubs[u]+1);
  }
  return true;
}

void go2(int u, int p) {
  int value;
  if(p < 0) {
    value = lbs[u];
    if((parity[u] & (1 << (value%2))) == 0) {
      ++value;
    }
  } else {
    value = lbs[parent]-1;
    if(value < lbs[u]) {
      value += 2;
    }
  }
  lbs[u] = ubs[u] = value;
  
  REP(i, g[u].size()) {
    int v = g[u][i];
    if(v == p)
      continue;
    go2(v, u);
  }
}

int main(void) {
  scanf("%d", &nNode);
  REP(i, nNode-1) {
    int a, b;
    scanf("%d%d", &a, &b);
    --a;
    --b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  REP(i, nNode) {
    parity[i] = 3;
    lbs[i] = 0;
    ubs[i] = 1000000;
  }
  int nInit;
  scanf("%d", &nInit);
  REP(i, nInit) {
    int v, p;
    scanf("%d%d", &v, &p);
    --v;
    lbs[v] = ubs[v] = p;
    parity[v] = 1 << (p % 2);
  }

  bool ok = go(0, -1);
  if(ok) {
    puts("Yes");
    go2(0);
    REP(i, nNode) {
      assert(lbs[i] == ubs[i]);
      printf("%d\n", lbs[i]);
    }
  } else {
    puts("No");
  }
  return 0;
}


Compiler output:
a.cc: In function 'void go2(int, int)':
a.cc:53:17: error: 'parent' was not declared in this scope
   53 |     value = lbs[parent]-1;
      |                 ^~~~~~
a.cc: In function 'int main()':
a.cc:96:8: error: too few arguments to function 'void go2(int, int)'
   96 |     go2(0);
      |     ~~~^~~
a.cc:45:6: note: declared here
   45 | void go2(int u, int p) {
      |      ^~~
Language: C++

#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
class DIJ{
	public:
	struct edge{
		int to,cost;
	};
	vector<vector<edge> >G;
	vp in;
	int n;
	vi d;//distance
	DIJ(int size){
		n=size;
		G=vector<vector<edge> >(n);
	}
	void add_edge(int a,int b,int c){
		edge e={b,c},ee={a,c};
		G[a].pb(e);
		G[b].pb(ee);
	}
	void dij(){
		d=vi(n,inf);
		priority_queue<pii>q;
		rep(i,in.size()){
			int a=in[i].first,b=in[i].second
			q.push(pii(-b,a-1));
			d[a-1]=b;
		}
		while(!q.empty()){
			pii p=q.top();
			q.pop();
			int pos=p.second,cost=-p.first;
			if(cost>d[pos])continue;
			rep(i,G[pos].size()){
				edge e=G[pos][i];
				int to=e.to;
				int nowcost=cost+e.cost;
				if(nowcost<d[to]){
					d[to]=nowcost;
					q.push(pii(-d[to],to));
				}
			}
		}
	}
	void solve(){
		rep(i,n-1){
			int a,b;
			cin>>a>>b;
			a--;b--;
			add_edge(a,b,1);
			add_edge(b,a,1);
		}
		int m;
		cin>>m;
		in=vp(m);
		rep(i,m)cin>>in[i].first>>in[i].second;
		dij();
		bool h=true;
		rep(i,n)rep(j,G[i].size()){
			int to=G[i][j].to;
			if(abs(d[i]-d[to])!=G[i][j].cost)h=false;
		}
		rep(i,m)if(in[i].second!=d[in.first-1])h=false;
		if(h){
			cout<<"Yes"<<endl;
			rep(i,n)cout<<d[i]<<endl;
		}else cout<<"No"<<endl;
	}
};
int main(){
	int n;
	cin>>n;
	DIJ dij(n);
	dij.solve();
}








Compiler output:
a.cc: In member function 'void DIJ::dij()':
a.cc:59:25: error: expected ',' or ';' before 'q'
   59 |                         q.push(pii(-b,a-1));
      |                         ^
a.cc: In member function 'void DIJ::solve()':
a.cc:96:47: error: 'vp' {aka 'class std::vector<std::pair<int, int> >'} has no member named 'first'
   96 |                 rep(i,m)if(in[i].second!=d[in.first-1])h=false;
      |                                               ^~~~~
Language: C++

#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
class DIJ{
	public:
	struct edge{
		int to,cost;
	};
	vector<vector<edge> >G;
	vp in;
	int n;
	vi d;//distance
	DIJ(int size){
		n=size;
		G=vector<vector<edge> >(n);
	}
	void add_edge(int a,int b,int c){
		edge e={b,c},ee={a,c};
		G[a].pb(e);
		G[b].pb(ee);
	}
	void dij(){
		d=vi(n,inf);
		priority_queue<pii>q;
		rep(i,m){
			int a=in[i].first,b=in[i].second
			q.push(pii(-b,a-1));
			d[a-1]=b;
		}
		while(!q.empty()){
			pii p=q.top();
			q.pop();
			int pos=p.second,cost=-p.first;
			if(cost>d[pos])continue;
			rep(i,G[pos].size()){
				edge e=G[pos][i];
				int to=e.to;
				int nowcost=cost+e.cost;
				if(nowcost<d[to]){
					d[to]=nowcost;
					q.push(pii(-d[to],to));
				}
			}
		}
	}
	void solve(){
		rep(i,n-1){
			int a,b;
			cin>>a>>b;
			a--;b--;
			add_edge(a,b,1);
			add_edge(b,a,1);
		}
		int m;
		cin>>m;
		in=vp(m);
		rep(i,m)cin>>in[i].first>>in[i].second;
		dij();
		bool h=true;
		rep(i,n)rep(j,G[i].size()){
			int to=G[i][j].to;
			if(abs(d[i]-d[to])!=G[i][j].cost)h=false;
		}
		rep(i,m)if(in[i].second!=d[in.first-1])h=false;
		if(h){
			cout<<"Yes"<<endl;
			rep(i,n)cout<<d[i]<<endl;
		}else cout<<"No"<<endl;
	}
};
int main(){
	int n;
	cin>>n;
	DIJ dij(n);
	dij.solve();
}








Compiler output:
a.cc: In member function 'void DIJ::dij()':
a.cc:57:23: error: 'm' was not declared in this scope; did you mean 'tm'?
   57 |                 rep(i,m){
      |                       ^
a.cc:15:35: note: in definition of macro 'loop'
   15 | #define loop(i,a,b) for(int i=a;i<b;i++)
      |                                   ^
a.cc:57:17: note: in expansion of macro 'rep'
   57 |                 rep(i,m){
      |                 ^~~
a.cc:59:25: error: expected ',' or ';' before 'q'
   59 |                         q.push(pii(-b,a-1));
      |                         ^
a.cc: In member function 'void DIJ::solve()':
a.cc:96:47: error: 'vp' {aka 'class std::vector<std::pair<int, int> >'} has no member named 'first'
   96 |                 rep(i,m)if(in[i].second!=d[in.first-1])h=false;
      |                                               ^~~~~
Language: C++

#include<bits/stdc++.h>
#include<climits>
#define FOR(i,a,b) for(int i = (a);i<=(b);i++)
#define ROF(i,a,b) for(int i = (a);i>=(b);i--)
#define MST(a,x) memset(a,x,sizeof(a))
#define ll long long
#define PB push_back
#define PH push
#define MP make_pair
#define FT first
#define SD second
#define N 100005
#define M 10005
#define INF 1000000007
#define MOD 1000000007
#define MOD2 1000000009
#define eps 1e-7
using namespace std;
inline int Max(int a,int b)
{
    return (((b-a)>>(32-1))&(a^b))^b;
}
inline int Min(int a,int b)
{
    return (((b-a)>>(32-1))&(a^b))^a;
}
int is_mul_overflow(ll a, ll b) {
        return LLONG_MAX / a < b;
}

vector<int>e[N];
pair<int,int>a[N];
int ans[N];
int merge(int x,int y)
{
    if(a[y].FT == -INF)return 1;
    auto u = MP(a[y].FT-1,a[y].SD+1);
    //cout<<x<<" "<<y<<" "<<a[x].FT<<" "<<a[x].SD<<" "<<u.FT<<" "<<u.SD<<endl;
    if(a[x].FT == -INF)a[x] = u;
    else if((a[x].FT+u.FT)%2)return 0;
    else if(a[x].FT>u.SD||u.FT>a[x].SD)return 0;
    else
    {
        a[x].FT = max(a[x].FT,u.FT);
        a[x].SD = min(a[x].SD,u.SD);
    }
    return 1;
}
int dfs(int u,int fa)
{
    int f = 1;
    for(auto v:e[u])
    {
        if(v == fa)continue;
        f&=dfs(v,u);
        f&=merge(u,v);
    }
    return f;
}
void dfs1(int u,int fa,int val)
{
    ans[u] = val;
    for(auto v:e[u])
    {
        if(v == fa)continue;
        int x;
        if((val+1)>=a[v].FT&&(val+1)<=a[v].SD&&(val+1+a[v].FT)%2 == 0)x = val+1;
        else if((val-1)>=a[v].FT&&(val-1)<=a[v].SD&&(val-1+a[v].FT)%2 == 0)x = val-1;
        else x = val-1;
        dfs1(v,u,x);
    }
}
int main()
{
     int size = 256 << 20; // 256MB
    char *p = (char*)malloc(size) + size;
    __asm__("movl %0, %%esp\n" :: "r"(p));
    cin.tie(0);
    ios::sync_with_stdio(false);
    //freopen("binary_02.txt","r",stdin);
    //freopen("binary_01_out.txt","w",stdout);
    int n,m;
    while(cin>>n)
    {
        FOR(i,1,n)e[i].clear();
        FOR(i,1,n)a[i] = MP(-INF,-INF);
        FOR(i,1,n-1)
        {
            int x,y;
            cin>>x>>y;
            e[x].PB(y);
            e[y].PB(x);
        }
        cin>>m;
        FOR(i,1,m)
        {
            int x,y;
            cin>>x>>y;
            a[x] = MP(y,y);
        }

        int f = dfs(1,-1);
       // FOR(i,1,n)cout<<i<<" i "<<a[i].FT<<" "<<a[i].SD<<endl;
        if(!f)cout<<"No"<<endl;
        else
        {
            cout<<"Yes"<<endl;
            dfs1(1,-1,a[1].FT);
            FOR(i,1,n)cout<<ans[i]<<endl;
        }
    }
    return 0;
}


Compiler output:
a.cc: Assembler messages:
a.cc:77: Error: operand type mismatch for `mov'