Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int v[100010],p[100010],lb[100010],ub[100010];
vector<int> G[100010];
bool f=false;
//根からDFS
//範囲を決定していく
void dfs(int i,int pr,int l,int r){
	if(p[i]!=-1){
		if(p[i]%2!=l%2||p[i]<l||p[i]>r){
			f=true;
			return;
		}
	}
	for(auto& e:G[i]){
		if(pr==e)continue;
		dfs(e,i,l-1,r+1);
		if(p[e]!=-1){
			lb[i]=max(l,p[e]-1);
			ub[i]=min(r,p[e]+1);
		}
	}
	if(lb[i]>ub[i]){
		f=true;
		retutn;
	}
	p[i]=lb[i];
}
int main(){
	int n;cin>>n;
	for(int i=0;i<n-1;i++){
		int a,b;cin>>a>>b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	int k;cin>>k;
	fill(p,p+n+1,-1);
	fill(lb,lb+n+1,-1);
	fill(ub,ub+n+1,INF);
	for(int i=0;i<k;i++){
		cin>>v[i];
		cin>>p[v[i]];
	}
	dfs(v[0],-1,p[v[0]],p[v[0]]);
	if(f){
		cout<<"No"<<endl;
		return 0;
	}
	cout<<"Yes"<<endl;
	
}
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int v[100010],p[100010],lb[100010],ub[100010];
vector<int> G[100010];
bool f=false;
//根からDFS
//範囲を決定していく
void dfs(int i,int pr,int l,int r){
	if(p[i]!=-1){
		if(p[i]%2!=l%2||p[i]<l||p[i]>r){
			f=true;
			return;
		}
	}
	for(auto& e:G[i]){
		if(pr==e)continue;
		dfs(e,i,l-1,r+1);
		if(p[e]!=-1){
			lb[i]=max(l,p[e]-1);
			ub[i]=min(r,p[e]+1);
		}
	}
	if(lb[i]>ub[i]){
		f=true;
		retutn;
	}
	p[i]=lb[i];
}
int main(){
	int n;cin>>n;
	for(int i=0;i<n-1;i++){
		int a,b;cin>>a>>b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	int k;cin>>k;
	fill(p,p+n+1,-1);
	fill(lb,lb+n+1,-1);
	fill(ub,ub+n+1,INF);
	for(int i=0;i<k;i++){
		cin>>v[i];
		cin>>p[v[i]];
	}
	dfs(v[0],-1,p[v[0]],p[v[0]]);
	if(f){
		cout<<"No"<<endl;
		return 0;
	}
	cout<<"Yes"<<endl;
	
}


Compiler output:
a.cc: In function 'void dfs(int, int, int, int)':
a.cc:27:17: error: 'retutn' was not declared in this scope
   27 |                 retutn;
      |                 ^~~~~~
a.cc: In function 'int main()':
a.cc:41:24: error: 'INF' was not declared in this scope
   41 |         fill(ub,ub+n+1,INF);
      |                        ^~~
a.cc: At global scope:
a.cc:58:5: error: redefinition of 'int v [100010]'
   58 | int v[100010],p[100010],lb[100010],ub[100010];
      |     ^
a.cc:5:5: note: 'int v [100010]' previously declared here
    5 | int v[100010],p[100010],lb[100010],ub[100010];
      |     ^
a.cc:58:15: error: redefinition of 'int p [100010]'
   58 | int v[100010],p[100010],lb[100010],ub[100010];
      |               ^
a.cc:5:15: note: 'int p [100010]' previously declared here
    5 | int v[100010],p[100010],lb[100010],ub[100010];
      |               ^
a.cc:58:25: error: redefinition of 'int lb [100010]'
   58 | int v[100010],p[100010],lb[100010],ub[100010];
      |                         ^~
a.cc:5:25: note: 'int lb [100010]' previously declared here
    5 | int v[100010],p[100010],lb[100010],ub[100010];
      |                         ^~
a.cc:58:36: error: redefinition of 'int ub [100010]'
   58 | int v[100010],p[100010],lb[100010],ub[100010];
      |                                    ^~
a.cc:5:36: note: 'int ub [100010]' previously declared here
    5 | int v[100010],p[100010],lb[100010],ub[100010];
      |                                    ^~
a.cc:59:13: error: redefinition of 'std::vector<int> G [100010]'
   59 | vector<int> G[100010];
      |             ^
a.cc:6:13: note: 'std::vector<int> G [100010]' previously declared here
    6 | vector<int> G[100010];
      |             ^
a.cc:60:6: error: redefinition of 'bool f'
   60 | bool f=false;
      |      ^
a.cc:7:6: note: 'bool f' previously defined here
    7 | bool f=false;
      |      ^
a.cc:63:6: error: redefinition of 'void dfs(int, int, int, int)'
   63 | void dfs(int i,int pr,int l,int r){
      |      ^~~
a.cc:10:6: note: 'void dfs(int, int, int, int)' previously defined here
   10 | void dfs(int i,int pr,int l,int r){
      |      ^~~
a.cc: In function 'void dfs(int, int, int, int)':
a.cc:80:17: error: 'retutn' was not declared in this scope
   80 |                 retutn;
      |                 ^~~~~~
a.cc: At global scope:
a.cc:84:5: error: redefinition of 'int main()'
   84 | int main(){
      |     ^~~~
a.cc:31:5: note: 'int main()' previously defined here
   31 | int main(){
      |     ^~~~
a.cc: In function 'int main()':
a.cc:94:24: error: 'INF' was not declared in this scope
   94 |         fill(ub,ub+n+1,INF);
      |                        ^~~