#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
vector<int>adj[MAXN];
void no(){
	puts("NO");
	exit(0);
}
ordered_set s;
int ans[MAXN],arr[MAXN];
void dfs(int nd){
	if(s.size()<=arr[nd])
		no();
	ans[nd]=*s.find_by_order(arr[nd]);
	s.erase(ans[nd]);
	tr(it,adj[nd])
		dfs(*it);
}
int main(){
    //freopen("file.in", "r", stdin);
    int n,root;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
    	s.insert(i);
    	int p;
		scanf("%d%d",&p,arr+i);
		if(!p)
			root=i;
		else
			adj[p].pb(i);
    }
    dfs(root);puts("YES");
    for(int i=1;i<=n;i++)
    	printf("%d ",ans[i]);
    puts("");
	return 0;
}


#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
vector<int>adj[MAXN];
int sub[MAXN];
void pre(int nd){
	sub[nd]=1;
	tr(it,adj[nd])
		pre(*it),sub[nd]+=sub[*it];
}
ordered_set s;
int ans[MAXN],arr[MAXN];
void dfs(int nd){
	ans[nd]=*s.find_by_order(arr[nd]);
	s.erase(ans[nd]);
	tr(it,adj[nd])
		dfs(*it);
}
int main(){
   //freopen("file.in", "r", stdin);
    int n,root;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
    	s.insert(i);
    	int p;
		scanf("%d%d",&p,arr+i);
		if(!p)
			root=i;
		else
			adj[p].pb(i);
    }
    pre(root);
    for(int i=1;i<=n;i++)
    	if(arr[i]>sub[i]){
    		puts("NO");
    		return 0;
    	}
    puts("YES");
    dfs(root);
    for(int i=1;i<=n;i++)
    	printf("%d ",ans[i]);
    puts("");
	return 0;
}


#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
vector<int>adj[MAXN];
int sub[MAXN];
void pre(int nd){
	sub[nd]=1;
	tr(it,adj[nd])
		pre(*it),sub[nd]+=sub[*it];
}
ordered_set s;
int ans[MAXN],arr[MAXN];
void dfs(int nd){
	ans[nd]=*s.find_by_order(arr[nd]);
	s.erase(ans[nd]);
	tr(it,adj[nd])
		dfs(*it);
}
int main(){
   //freopen("file.in", "r", stdin);
    int n,root;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
    	s.insert(i);
    	int p;
		scanf("%d%d",&p,arr+i);
		if(!p)
			root=i;
		else
			adj[p].pb(i);
    }
    pre(root);
    for(int i=1;i<=n;i++)
    	if(arr[i]+1>sub[i]){
    		puts("NO");
    		return 0;
    	}
    puts("YES");
    dfs(root);
    for(int i=1;i<=n;i++)
    	printf("%d ",ans[i]);
    puts("");
	return 0;
}


#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
typedef long long ll;
const int maxn=2007;
int p[maxn], c[maxn];
vector<int> v[maxn];
int sum[maxn];
int y=3e8, y1=3e8-100000;
int deal(int x, set<int> &s)
{
    for(int i=0; i<v[x].size(); i++)
    {
        set<int> s1;
        if(deal(v[x][i], s1))
        {
            for(auto j : s1) s.insert(j);
        }
        else return 0;
    }
    if(c[x]>s.size()) return 0;
    else
    {
        int cnt=0;
        int u=0, v=0;
        for(auto i : s)
        {
            cnt++;
            if(cnt==c[x]) u=i;
            if(cnt==c[x]+1) v=i;
        }
        if(c[x]==0) sum[x]=y1, y1-=100000;
        else if(c[x]==s.size()) sum[x]=y, y+=100000;
        else sum[x]=(u+v)/2;
        s.insert(sum[x]);
        return 1;
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, j;
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        cin>>p[i]>>c[i];
        if(p[i]==0) j=i;
        v[p[i]].push_back(i);
    }
    set<int> s;
    if(deal(j, s))
    {
        cout<<"YES"<<endl;
        for(int i=1; i<=n; i++)
            cout<<sum[i]<<" ";
        cout<<endl;
    }
    else cout<<"NO"<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
typedef long long ll;
const int maxn=2007;
int p[maxn], c[maxn];
vector<int> v[maxn];
int sum[maxn];
int y=3e8, y1=3e8-100000;
int deal(int x, set<int> &s)
{
    if(v[x].size()==0)
    {
        sum[x]=y;
        y+=100000;
        s.insert(sum[x]);
        if(c[x]==0) return 1;
        else return 0;
    }
    for(int i=0; i<v[x].size(); i++)
    {
        set<int> s1;
        if(deal(v[x][i], s1))
        {
            for(auto j : s1)
                s.insert(j);
        }
        else return 0;
    }
    if(c[x]>s.size()) return 0;
    else
    {
        int cnt=0;
        int u=0, v=0;
        for(auto i : s)
        {
            cnt++;
            if(cnt==c[x]) u=i;
            if(cnt==c[x]+1) v=i;
        }
        //if(c[x]==0) sum[x]=y1, y1-=100000;
        if(v==0) sum[x]=y, y+=100000;
        else sum[x]=(u+v+1)/2;
        s.insert(sum[x]);
        return 1;
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, j;
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        cin>>p[i]>>c[i];
        if(p[i]==0) j=i;
        v[p[i]].push_back(i);
    }
    set<int> s;
    if(deal(j, s))
    {
        cout<<"YES"<<endl;
        for(int i=1; i<=n; i++)
            cout<<sum[i]<<" ";
        cout<<endl;
    }
    else cout<<"NO"<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
typedef long long ll;
const int maxn=2007;
int p[maxn], c[maxn];
vector<int> v[maxn];
int sum[maxn];
int y=1e7;
int deal(int x, set<int> &s)
{
    //cout<<x<<" **"<<endl;
    //getchar();
    if(v[x].size()==0)
    {
        sum[x]=y;
        y+=5000;
        s.insert(sum[x]);
        return 1;
    }
    for(int i=0; i<v[x].size(); i++)
        if(deal(v[x][i], s)) continue;
        else return 0;
    if(c[x]>s.size()) return 0;
    else
    {
        int cnt=0;
        int u=0, v=0;
        for(auto i : s)
        {
            cnt++;
            if(cnt==c[x]) u=i;
            if(cnt==c[x]+1) v=i;
        }
        if(v==0)
        {
            sum[x]=y;
            y+=5000;
        }
        else sum[x]=(u+v+1)/2;
        s.insert(sum[x]);
        return 1;
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        cin>>p[i]>>c[i];
        v[p[i]].push_back(i);
    }
    set<int> s;
    if(deal(0, s))
    {
        cout<<"YES"<<endl;
        for(int i=1; i<=n; i++)
            cout<<sum[i]<<" ";
        cout<<endl;
    }
    else cout<<"NO"<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
typedef long long ll;
const int maxn=2007;
int p[maxn], c[maxn];
vector<int> v[maxn];
int sum[maxn];
int y=3e7;
int deal(int x, set<int> &s)
{
    if(v[x].size()==0)
    {
        sum[x]=y;
        y+=10000;
        s.insert(sum[x]);
        if(c[x]==0) return 1;
        else return 0;
    }
    for(int i=0; i<v[x].size(); i++)
    {
        set<int> s1;
        if(deal(v[x][i], s1))
        {
            for(auto j : s1)
                s.insert(j);
        }
        else return 0;
    }
    if(c[x]>s.size()) return 0;
    else
    {
        int cnt=0;
        int u=0, v=0;
        for(auto i : s)
        {
            cnt++;
            if(cnt==c[x]) u=i;
            if(cnt==c[x]+1) v=i;
        }
        if(c[x]==0) sum[x]=*s.begin(), sum[x]-=10000;
        else if(v==0) sum[x]=y, y+=10000;
        else sum[x]=(u+v+1)/2;
        s.insert(sum[x]);
        return 1;
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        cin>>p[i]>>c[i];
        v[p[i]].push_back(i);
    }
    set<int> s;
    if(deal(0, s))
    {
        cout<<"YES"<<endl;
        for(int i=1; i<=n; i++)
            cout<<sum[i]<<" ";
        cout<<endl;
    }
    else cout<<"NO"<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
typedef long long ll;
const int maxn=2007;
int p[maxn], c[maxn];
vector<int> v[maxn];
int sum[maxn];
int y=1e7;
int deal(int x, set<int> &s)
{
    //cout<<x<<" **"<<endl;
    //getchar();
    if(v[x].size()==0)
    {
        sum[x]=y;
        y+=10000;
        s.insert(sum[x]);
        if(c[x]==0) return 1;
        else return 0;
    }
    for(int i=0; i<v[x].size(); i++)
    {
        set<int> s1;
        if(deal(v[x][i], s1))
        {
            for(auto j : s1)
                s.insert(j);
        }
        else return 0;
    }
    if(c[x]>s.size()) return 0;
    else
    {
        int cnt=0;
        int u=0, v=0;
        for(auto i : s)
        {
            cnt++;
            if(cnt==c[x]) u=i;
            if(cnt==c[x]+1) v=i;
        }
        if(v==0)
        {
            sum[x]=y;
            y+=5000;
        }
        else sum[x]=(u+v+1)/2;
        s.insert(sum[x]);
        return 1;
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        cin>>p[i]>>c[i];
        v[p[i]].push_back(i);
    }
    set<int> s;
    if(deal(0, s))
    {
        cout<<"YES"<<endl;
        for(int i=1; i<=n; i++)
            cout<<sum[i]<<" ";
        cout<<endl;
    }
    else cout<<"NO"<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
typedef long long ll;
const int maxn=2007;
int c[maxn], n;
vector<int> v[maxn];
set<int> s;
int sum[maxn];
int deal(int x)
{
    int cnt=0;
    for(auto j : s)
    {
        if(c[x]==cnt) { sum[x]=j; s.erase(j); break; }
        cnt++;
    }
    if(sum[x]==0) return 0;
    for(int i=0; i<v[x].size(); i++)
        if(!deal(v[x][i])) return 0;
    return 1;
}
int dfs(int x, int y)
{
    int cnt=0;
    for(int i=0; i<v[x].size(); i++)
    {
        if(sum[v[x][i]]<y) cnt++;
        cnt+=dfs(v[x][i], y);
    }
    return cnt;
}
int check()
{
    for(int i=1; i<=n; i++)
        if(dfs(i, sum[i])!=c[i]) return 0;
    return 1;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int p, j;
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        s.insert(i);
        cin>>p>>c[i];
        if(p==0) j=i;
        v[p].push_back(i);
    }
    if(deal(j) && check())
    {
        cout<<"YES"<<endl;
        for(int i=1; i<=n; i++)
            cout<<sum[i]<<" ";
        cout<<endl;
    }
    else cout<<"NO"<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
typedef long long ll;
const int maxn=2007;
int p[maxn], c[maxn];
vector<int> v[maxn];
int sum[maxn];
int y=3e7, y1=3e7-10000;
int deal(int x, set<int> &s)
{
    if(v[x].size()==0)
    {
        sum[x]=y;
        y+=10000;
        s.insert(sum[x]);
        if(c[x]==0) return 1;
        else return 0;
    }
    for(int i=0; i<v[x].size(); i++)
    {
        set<int> s1;
        if(deal(v[x][i], s1))
        {
            for(auto j : s1)
                s.insert(j);
        }
        else return 0;
    }
    if(c[x]>s.size()) return 0;
    else
    {
        int cnt=0;
        int u=0, v=0;
        for(auto i : s)
        {
            cnt++;
            if(cnt==c[x]) u=i;
            if(cnt==c[x]+1) v=i;
        }
        if(c[x]==0) sum[x]=y1, y1-=10000;
        else if(v==0) sum[x]=y, y+=10000;
        else sum[x]=(u+v+1)/2;
        s.insert(sum[x]);
        return 1;
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        cin>>p[i]>>c[i];
        v[p[i]].push_back(i);
    }
    set<int> s;
    if(deal(0, s))
    {
        cout<<"YES"<<endl;
        for(int i=1; i<=n; i++)
            cout<<sum[i]<<" ";
        cout<<endl;
    }
    else cout<<"NO"<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
typedef long long ll;
const int maxn=2007;
int p[maxn], c[maxn];
vector<int> v[maxn];
int sum[maxn];
int y=3e8, y1=3e8-100000;
int deal(int x, set<int> &s)
{
    if(v[x].size()==0)
    {
        sum[x]=y;
        y+=100000;
        s.insert(sum[x]);
        if(c[x]==0) return 1;
        else return 0;
    }
    for(int i=0; i<v[x].size(); i++)
    {
        set<int> s1;
        if(deal(v[x][i], s1))
        {
            for(auto j : s1)
                s.insert(j);
        }
        else return 0;
    }
    if(c[x]>s.size()) return 0;
    else
    {
        int cnt=0;
        int u=0, v=0;
        for(auto i : s)
        {
            cnt++;
            if(cnt==c[x]) u=i;
            if(cnt==c[x]+1) v=i;
        }
        if(c[x]==0) sum[x]=y1, y1-=100000;
        else if(c[x]==s.size()) sum[x]=y, y+=100000;
        else sum[x]=(u+v+1)/2;
        s.insert(sum[x]);
        return 1;
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, j;
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        cin>>p[i]>>c[i];
        if(p[i]==0) j=i;
        v[p[i]].push_back(i);
    }
    set<int> s;
    if(deal(j, s))
    {
        cout<<"YES"<<endl;
        for(int i=1; i<=n; i++)
            cout<<sum[i]<<" ";
        cout<<endl;
    }
    else cout<<"NO"<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
typedef long long ll;
const int maxn=2007;
int p[maxn], c[maxn];
vector<int> v[maxn];
int sum[maxn];
int y=1e7;
int deal(int x, set<int> &s)
{
    //cout<<x<<" **"<<endl;
    //getchar();
    if(v[x].size()==0)
    {
        sum[x]=y;
        y+=5000;
        s.insert(sum[x]);
        return 1;
    }
    for(int i=0; i<v[x].size(); i++)
    {
        set<int> s1;
        if(deal(v[x][i], s1))
        {
            for(auto j : s1)
                s.insert(j);
        }
        else return 0;
    }
    if(c[x]>s.size()) return 0;
    else
    {
        int cnt=0;
        int u=0, v=0;
        for(auto i : s)
        {
            cnt++;
            if(cnt==c[x]) u=i;
            if(cnt==c[x]+1) v=i;
        }
        if(v==0)
        {
            sum[x]=y;
            y+=5000;
        }
        else sum[x]=(u+v+1)/2;
        s.insert(sum[x]);
        return 1;
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        cin>>p[i]>>c[i];
        v[p[i]].push_back(i);
    }
    set<int> s;
    if(deal(0, s))
    {
        cout<<"YES"<<endl;
        for(int i=1; i<=n; i++)
            cout<<sum[i]<<" ";
        cout<<endl;
    }
    else cout<<"NO"<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
typedef long long ll;
const int maxn=2007;
int c[maxn], n;
vector<int> v[maxn];
set<int> s;
int sum[maxn];
int deal(int x)
{
    int cnt=0;
    for(auto j : s)
    {
        if(c[x]==cnt) { sum[x]=j; s.erase(j); break; }
        cnt++;
    }
    if(sum[x]==0) return 0;
    for(int i=0; i<v[x].size(); i++)
        if(!deal(v[x][i])) return 0;
    return 1;
}
int dfs(int x, int y)
{
    int cnt=0;
    for(int i=0; i<v[x].size(); i++)
    {
        if(sum[v[x][i]]<y) cnt++;
        cnt+=dfs(v[x][i], y);
    }
    return cnt;
}
int check()
{
    for(int i=1; i<=n; i++)
        if(dfs(i, sum[i])!=c[i]) return 0;
    else return 1;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int p, j;
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        s.insert(i);
        cin>>p>>c[i];
        if(p==0) j=i;
        v[p].push_back(i);
    }
    if(deal(j) && check())
    {
        cout<<"YES"<<endl;
        for(int i=1; i<=n; i++)
            cout<<sum[i]<<" ";
        cout<<endl;
    }
    else cout<<"NO"<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
typedef long long ll;
const int maxn=2007;
int p[maxn], c[maxn];
vector<int> v[maxn];
int sum[maxn];
int y=3e7;
int deal(int x, set<int> &s)
{
    //cout<<x<<" **"<<endl;
    //getchar();
    if(v[x].size()==0)
    {
        sum[x]=y;
        y+=10000;
        s.insert(sum[x]);
        if(c[x]==0) return 1;
        else return 0;
    }
    for(int i=0; i<v[x].size(); i++)
    {
        set<int> s1;
        if(deal(v[x][i], s1))
        {
            for(auto j : s1)
                s.insert(j);
        }
        else return 0;
    }
    if(c[x]>s.size()) return 0;
    else
    {
        int cnt=0;
        int u=0, v=0;
        for(auto i : s)
        {
            cnt++;
            if(cnt==c[x]) u=i;
            if(cnt==c[x]+1) v=i;
        }
        if(c[x]==0)
        {
            sum[x]=*s.begin();
            sum[x]-=10000;
        }
        else if(v==0)
        {
            sum[x]=y;
            y+=5000;
        }
        else sum[x]=(u+v+1)/2;
        s.insert(sum[x]);
        return 1;
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        cin>>p[i]>>c[i];
        v[p[i]].push_back(i);
    }
    set<int> s;
    if(deal(0, s))
    {
        cout<<"YES"<<endl;
        for(int i=1; i<=n; i++)
            cout<<sum[i]<<" ";
        cout<<endl;
    }
    else cout<<"NO"<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
typedef long long ll;
const int maxn=2007;
int p[maxn], c[maxn];
vector<int> v[maxn];
int sum[maxn];
int y=3e8, y1=3e8-100000;
int deal(int x, set<int> &s)
{
    for(int i=0; i<v[x].size(); i++)
    {
        set<int> s1;
        if(deal(v[x][i], s1))
        {
            for(auto j : s1) s.insert(j);
        }
        else return 0;
    }
    if(c[x]>s.size()) return 0;
    else
    {
        int cnt=0;
        int u=0, v=0;
        for(auto i : s)
        {
            cnt++;
            if(cnt==c[x]) u=i;
            if(cnt==c[x]+1) v=i;
        }
        if(c[x]==s.size()) sum[x]=y, y+=100000;
        else if(c[x]==0) sum[x]=y1, y1-=100000;
        else sum[x]=(u+v)/2;
        s.insert(sum[x]);
        return 1;
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, j;
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        cin>>p[i]>>c[i];
        if(p[i]==0) j=i;
        v[p[i]].push_back(i);
    }
    set<int> s;
    if(deal(j, s))
    {
        cout<<"YES"<<endl;
        for(int i=1; i<=n; i++)
            cout<<sum[i]<<" ";
        cout<<endl;
    }
    else cout<<"NO"<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
typedef long long ll;
const int maxn=2007;
int p[maxn], c[maxn];
vector<int> v[maxn];
int sum[maxn];
int y=3e8, y1=3e8-100000;
int deal(int x, set<int> &s)
{
    if(v[x].size()==0)
    {
        sum[x]=y;
        y+=100000;
        s.insert(sum[x]);
        if(c[x]==0) return 1;
        else return 0;
    }
    for(int i=0; i<v[x].size(); i++)
    {
        set<int> s1;
        if(deal(v[x][i], s1))
        {
            for(auto j : s1)
                s.insert(j);
        }
        else return 0;
    }
    if(c[x]>s.size()) return 0;
    else
    {
        int cnt=0;
        int u=0, v=0;
        for(auto i : s)
        {
            cnt++;
            if(cnt==c[x]) u=i;
            if(cnt==c[x]+1) v=i;
        }
        if(c[x]==0) sum[x]=y1, y1-=100000;
        else if(v==0) sum[x]=y, y+=100000;
        else sum[x]=(u+v+1)/2;
        s.insert(sum[x]);
        return 1;
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, j;
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        cin>>p[i]>>c[i];
        if(p[i]==0) j=i;
        v[p[i]].push_back(i);
    }
    set<int> s;
    if(deal(j, s))
    {
        cout<<"YES"<<endl;
        for(int i=1; i<=n; i++)
            cout<<sum[i]<<" ";
        cout<<endl;
    }
    else cout<<"NO"<<endl;
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sstream>
#include <iostream>
#include <math.h>
#include <time.h>
#include <unistd.h>
#include <algorithm>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <string>
#include <immintrin.h>
#ifndef ONLINE_JUDGE
	#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#else
	#define DEBUG(x) do {} while(0);
#endif

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define FOR(i, A, N) for(int (i) = (A); (i) < (N); (i)++)
#define REP(i, N) for(int (i) = 0; (i) < (N); (i)++)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#define ALIGN(x) __attribute__((aligned(x)))
using namespace std;
typedef long long ll;
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

int n,m;
vector<int> sons[2222];
int ASS[2222];
int P[2222];
int C[2222];
int known[2222];

void dfs(int curr, vector<int>& suball, int start = 1) {
	if(!start) suball.pb(ASS[curr]);
	for(int s : sons[curr]) {
		dfs(s, suball, 0);
	}
}
void dec(int curr, int val, int start = 1) {
	if(!start && ASS[curr] <= val) ASS[curr]--;
	for(int s : sons[curr]) {
		dec(s, val, 0);
	}
}

int main() {
	scanf("%d", &n);
	int root = 0;
	REP(i, n) {
		scanf("%d%d", P+i, C+i);
		P[i]--;
		if(P[i] == -1)
			root = i;
		else
			sons[P[i]].pb(i);
	}
	queue<int> Q;
	REP(i, n) {
		if(sons[i].size() == 0) {
			Q.push(i);
		}
	}
	int leafs = 1;
	int mini = 0;
	while(!Q.empty()) {
		int c = Q.front();
		Q.pop();
		if(sons[c].size() == 0) {
			ASS[c] = leafs*100000;
			leafs++;
			known[P[c]]++;
			if(known[P[c]] == sons[P[c]].size()) {
				Q.push(P[c]);
			}
		} else {
			vector<int> suball;
			dfs(c, suball);
			sort(suball.begin(), suball.end());
			if(C[c] == 0) {
				ASS[c] = suball[0]-1;
			} else if(C[c] == suball.size()) {
				ASS[c] = suball[suball.size()-1]+1;
			} else if(C[c] < suball.size()) {
				dec(c, suball[C[c]-1]);
				ASS[c] = suball[C[c]-1];
			} else {
				printf("NO\n");
				return 0;
			}
			mini = min(mini, ASS[c]);

			if(P[c] != -1) {
				known[P[c]]++;
				if(known[P[c]] == sons[P[c]].size()) {
					Q.push(P[c]);
				}
			}
		}
	}
	printf("YES\n");
	REP(i, n) printf("%d ", ASS[i]-mini+1);

	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sstream>
#include <iostream>
#include <math.h>
#include <time.h>
#include <unistd.h>
#include <algorithm>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <string>
#include <immintrin.h>
#ifndef ONLINE_JUDGE
	#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#else
	#define DEBUG(x) do {} while(0);
#endif

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define FOR(i, A, N) for(int (i) = (A); (i) < (N); (i)++)
#define REP(i, N) for(int (i) = 0; (i) < (N); (i)++)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#define ALIGN(x) __attribute__((aligned(x)))
using namespace std;
typedef long long ll;
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

int n,m;
vector<int> sons[2222];
int ASS[2222];
int P[2222];
int C[2222];
int known[2222];

void dfs(int curr, vector<int>& suball, int start = 1) {
	if(!start) suball.pb(ASS[curr]);
	for(int s : sons[curr]) {
		dfs(s, suball, 0);
	}
}
void dec(int curr, int val, int start = 1) {
	if(!start && ASS[curr] <= val) ASS[curr]--;
	for(int s : sons[curr]) {
		dec(s, val, 0);
	}
}
int cnt(int curr) {
	int ans = 1;
	for(int s : sons[curr])
		ans += cnt(s);
	return ans;
}
void inc(int curr, int val = 0, int start = 1) {
	int X = 0;
	if(!start) ASS[curr] += val;
	for(int s : sons[curr]) {
		if(start) {
			if(X) inc(s, X, 0);
			X += cnt(s);
		}
		else {
			inc(s, X, 0);
		}
	}
}

int main() {
	scanf("%d", &n);
	int root = 0;
	REP(i, n) {
		scanf("%d%d", P+i, C+i);
		P[i]--;
		if(P[i] == -1)
			root = i;
		else
			sons[P[i]].pb(i);
	}
	queue<int> Q;
	REP(i, n) {
		if(sons[i].size() == 0) {
			Q.push(i);
		}
	}
	int leafs = 1;
	int mini = 0;
	while(!Q.empty()) {
		int c = Q.front();
		Q.pop();
		if(sons[c].size() == 0) {
			if(C[c]!= 0) {
				printf("NO\n");
				return 0;
			}
			ASS[c] = 1;
			known[P[c]]++;
			if(known[P[c]] == sons[P[c]].size()) {
				Q.push(P[c]);
			}
		} else {
			vector<int> suball;
			inc(c);
			dfs(c, suball);
			sort(suball.begin(), suball.end());
			int last = -1000000;
			for(int X : suball) {
				assert(X != last);
				last = X;
			}
			if(C[c] == 0) {
				ASS[c] = suball[0]-1;
			} else if(C[c] == suball.size()) {
				ASS[c] = suball[suball.size()-1]+1;
			} else if(C[c] < suball.size()) {
				dec(c, suball[C[c]-1]);
				ASS[c] = suball[C[c]-1];
			} else {
				printf("NO\n");
				return 0;
			}
			mini = min(mini, ASS[c]);

			if(P[c] != -1) {
				known[P[c]]++;
				if(known[P[c]] == sons[P[c]].size()) {
					Q.push(P[c]);
				}
			}
		}
	}
	printf("YES\n");
	REP(i, n) mini = min(ASS[i], mini);
	REP(i, n) printf("%d ", ASS[i]-mini+1);

	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sstream>
#include <iostream>
#include <math.h>
#include <time.h>
#include <unistd.h>
#include <algorithm>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <string>
#include <immintrin.h>
#ifndef ONLINE_JUDGE
	#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#else
	#define DEBUG(x) do {} while(0);
#endif

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define FOR(i, A, N) for(int (i) = (A); (i) < (N); (i)++)
#define REP(i, N) for(int (i) = 0; (i) < (N); (i)++)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#define ALIGN(x) __attribute__((aligned(x)))
using namespace std;
typedef long long ll;
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

int n,m;
vector<int> sons[2222];
int ASS[2222];
int P[2222];
int C[2222];
int known[2222];

void dfs(int curr, vector<int>& suball, int start = 1) {
	if(!start) suball.pb(ASS[curr]);
	for(int s : sons[curr]) {
		dfs(s, suball, 0);
	}
}
void dec(int curr, int val, int start = 1) {
	if(!start && ASS[curr] <= val) ASS[curr]--;
	for(int s : sons[curr]) {
		dec(s, val, 0);
	}
}
int cnt(int curr) {
	int ans = 1;
	for(int s : sons[curr])
		ans += cnt(s);
	return ans;
}
void inc(int curr, int val = 0, int start = 1) {
	int X = 0;
	if(!start) ASS[curr] += val;
	for(int s : sons[curr]) {
		if(start) {
			if(X) inc(s, X, 0);
			X += cnt(s);
		}
		else {
			inc(s, X, 0);
		}
	}
}

int main() {
	scanf("%d", &n);
	int root = 0;
	REP(i, n) {
		scanf("%d%d", P+i, C+i);
		P[i]--;
		if(P[i] == -1)
			root = i;
		else
			sons[P[i]].pb(i);
	}
	queue<int> Q;
	REP(i, n) {
		if(sons[i].size() == 0) {
			Q.push(i);
		}
	}
	int leafs = 1;
	int mini = 0;
	while(!Q.empty()) {
		int c = Q.front();
		Q.pop();
		if(sons[c].size() == 0) {
			if(C[c]!= 0) {
				printf("NO\n");
				return 0;
			}
			ASS[c] = 1;
			leafs++;
			known[P[c]]++;
			if(known[P[c]] == sons[P[c]].size()) {
				Q.push(P[c]);
			}
		} else {
			vector<int> suball;
			inc(c);
			dfs(c, suball);
			sort(suball.begin(), suball.end());
			if(C[c] == 0) {
				ASS[c] = suball[0]-1;
			} else if(C[c] == suball.size()) {
				ASS[c] = suball[suball.size()-1]+1;
			} else if(C[c] < suball.size()) {
				dec(c, suball[C[c]-1]);
				ASS[c] = suball[C[c]-1];
			} else {
				printf("NO\n");
				return 0;
			}
			mini = min(mini, ASS[c]);

			if(P[c] != -1) {
				known[P[c]]++;
				if(known[P[c]] == sons[P[c]].size()) {
					Q.push(P[c]);
				}
			}
		}
	}
	printf("YES\n");
	REP(i, n) mini = min(ASS[i], mini);
	REP(i, n) printf("%d ", ASS[i]-mini+1);

	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sstream>
#include <iostream>
#include <math.h>
#include <time.h>
#include <unistd.h>
#include <cassert>
#include <algorithm>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <string>
#include <immintrin.h>
#ifndef ONLINE_JUDGE
	#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#else
	#define DEBUG(x) do {} while(0);
#endif

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define FOR(i, A, N) for(int (i) = (A); (i) < (N); (i)++)
#define REP(i, N) for(int (i) = 0; (i) < (N); (i)++)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#define ALIGN(x) __attribute__((aligned(x)))
using namespace std;
typedef long long ll;
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

int n,m;
vector<int> sons[2222];
int ASS[2222];
int P[2222];
int C[2222];
int known[2222];

void dfs(int curr, vector<int>& suball, int start = 1) {
	if(!start) suball.pb(ASS[curr]);
	for(int s : sons[curr]) {
		dfs(s, suball, 0);
	}
}
void dec(int curr, int val, int start = 1) {
	if(!start && ASS[curr] <= val) ASS[curr]--;
	for(int s : sons[curr]) {
		dec(s, val, 0);
	}
}
int cnt(int curr) {
	int ans = 1;
	for(int s : sons[curr])
		ans += cnt(s);
	return ans;
}
void inc(int curr, int val = 0, int start = 1) {
	int X = 0;
	if(!start) ASS[curr] += val;
	for(int s : sons[curr]) {
		if(start) {
			if(X) inc(s, X, 0);
			X += cnt(s);
		}
		else {
			inc(s, X, 0);
		}
	}
}

int main() {
	scanf("%d", &n);
	int root = 0;
	REP(i, n) {
		scanf("%d%d", P+i, C+i);
		P[i]--;
		if(P[i] == -1)
			root = i;
		else
			sons[P[i]].pb(i);
	}
	queue<int> Q;
	REP(i, n) {
		if(sons[i].size() == 0) {
			Q.push(i);
		}
	}
	int leafs = 1;
	int mini = 0;
	while(!Q.empty()) {
		int c = Q.front();
		Q.pop();
		if(sons[c].size() == 0) {
			if(C[c]!= 0) {
				printf("NO\n");
				return 0;
			}
			ASS[c] = 1;
			known[P[c]]++;
			if(known[P[c]] == sons[P[c]].size()) {
				Q.push(P[c]);
			}
		} else {
			vector<int> suball;
			inc(c);
			dfs(c, suball);
			sort(suball.begin(), suball.end());
			int last = -1000000;
			for(int X : suball) {
				assert(X != last);
				last = X;
			}
			if(C[c] == 0) {
				ASS[c] = suball[0]-1;
			} else if(C[c] == suball.size()) {
				ASS[c] = suball[suball.size()-1]+1;
			} else if(C[c] < suball.size()) {
				dec(c, suball[C[c]-1]);
				ASS[c] = suball[C[c]-1];
			} else {
				printf("NO\n");
				return 0;
			}
			mini = min(mini, ASS[c]);

			if(P[c] != -1) {
				known[P[c]]++;
				if(known[P[c]] == sons[P[c]].size()) {
					Q.push(P[c]);
				}
			}
		}
	}
	printf("YES\n");
	REP(i, n) mini = min(ASS[i], mini);
	REP(i, n) printf("%d ", ASS[i]-mini+1);

	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sstream>
#include <iostream>
#include <math.h>
#include <time.h>
#include <unistd.h>
#include <algorithm>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <string>
#include <immintrin.h>
#ifndef ONLINE_JUDGE
	#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#else
	#define DEBUG(x) do {} while(0);
#endif

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define FOR(i, A, N) for(int (i) = (A); (i) < (N); (i)++)
#define REP(i, N) for(int (i) = 0; (i) < (N); (i)++)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#define ALIGN(x) __attribute__((aligned(x)))
using namespace std;
typedef long long ll;
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

int n,m;
vector<int> sons[2222];
int ASS[2222];
int P[2222];
int C[2222];
int known[2222];

void dfs(int curr, vector<int>& suball, int start = 1) {
	if(!start) suball.pb(ASS[curr]);
	for(int s : sons[curr]) {
		dfs(s, suball, 0);
	}
}
void dec(int curr, int val, int start = 1) {
	if(!start && ASS[curr] <= val) ASS[curr]--;
	for(int s : sons[curr]) {
		dec(s, val, 0);
	}
}
int cnt(int curr) {
	int ans = 1;
	for(int s : sons[curr])
		ans += cnt(s);
	return ans;
}
void inc(int curr, int val = 0, int start = 1) {
	int X = 0;
	if(!start) ASS[curr] += val;
	for(int s : sons[curr]) {
		if(start) {
			if(X) inc(s, X, 0);
			X += cnt(s);
		}
		else {
			inc(s, X, 0);
		}
	}
}

int main() {
	scanf("%d", &n);
	int root = 0;
	REP(i, n) {
		scanf("%d%d", P+i, C+i);
		P[i]--;
		if(P[i] == -1)
			root = i;
		else
			sons[P[i]].pb(i);
	}
	queue<int> Q;
	REP(i, n) {
		if(sons[i].size() == 0) {
			Q.push(i);
		}
	}
	int leafs = 1;
	int mini = 0;
	while(!Q.empty()) {
		int c = Q.front();
		Q.pop();
		if(sons[c].size() == 0) {
			ASS[c] = 1;
			leafs++;
			known[P[c]]++;
			if(known[P[c]] == sons[P[c]].size()) {
				Q.push(P[c]);
			}
		} else {
			vector<int> suball;
			inc(c);
			dfs(c, suball);
			sort(suball.begin(), suball.end());
			if(C[c] == 0) {
				ASS[c] = suball[0]-1;
			} else if(C[c] == suball.size()) {
				ASS[c] = suball[suball.size()-1]+1;
			} else if(C[c] < suball.size()) {
				dec(c, suball[C[c]-1]);
				ASS[c] = suball[C[c]-1];
			} else {
				printf("NO\n");
				return 0;
			}
			mini = min(mini, ASS[c]);

			if(P[c] != -1) {
				known[P[c]]++;
				if(known[P[c]] == sons[P[c]].size()) {
					Q.push(P[c]);
				}
			}
		}
	}
	printf("YES\n");
	REP(i, n) mini = min(ASS[i], mini);
	REP(i, n) printf("%d ", ASS[i]-mini+1);

	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sstream>
#include <iostream>
#include <math.h>
#include <time.h>
#include <unistd.h>
#include <algorithm>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <string>
#include <immintrin.h>
#ifndef ONLINE_JUDGE
	#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#else
	#define DEBUG(x) do {} while(0);
#endif

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define FOR(i, A, N) for(int (i) = (A); (i) < (N); (i)++)
#define REP(i, N) for(int (i) = 0; (i) < (N); (i)++)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#define ALIGN(x) __attribute__((aligned(x)))
using namespace std;
typedef long long ll;
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

int n,m;
vector<int> sons[2222];
int ASS[2222];
int P[2222];
int C[2222];
int known[2222];

void dfs(int curr, vector<int>& suball, int start = 1) {
	if(!start) suball.pb(ASS[curr]);
	for(int s : sons[curr]) {
		dfs(s, suball, 0);
	}
}
void dec(int curr, int val, int start = 1) {
	if(!start && ASS[curr] <= val) ASS[curr]--;
	for(int s : sons[curr]) {
		dec(s, val, 0);
	}
}

int main() {
	scanf("%d", &n);
	int root = 0;
	REP(i, n) {
		scanf("%d%d", P+i, C+i);
		P[i]--;
		if(P[i] == -1)
			root = i;
		else
			sons[P[i]].pb(i);
	}
	queue<int> Q;
	REP(i, n) {
		if(sons[i].size() == 0) {
			Q.push(i);
		}
	}
	int leafs = 1;
	int mini = 0;
	while(!Q.empty()) {
		int c = Q.front();
		Q.pop();
		if(sons[c].size() == 0) {
			ASS[c] = leafs*100000;
			leafs++;
			known[P[c]]++;
			if(known[P[c]] == sons[P[c]].size()) {
				Q.push(P[c]);
			}
		} else {
			vector<int> suball;
			dfs(c, suball);
			sort(suball.begin(), suball.end());
			if(C[c] == 0) {
				ASS[c] = suball[0]-1;
			} else if(C[c] == suball.size()) {
				ASS[c] = suball[suball.size()-1]+1;
			} else if(C[c] < suball.size()) {
				dec(c, suball[C[c]-1]);
				ASS[c] = suball[C[c]-1];
			} else {
				printf("NO\n");
				return 0;
			}
			mini = min(mini, ASS[c]);

			if(P[c] != -1) {
				known[P[c]]++;
				if(known[P[c]] == sons[P[c]].size()) {
					Q.push(P[c]);
				}
			}
		}
	}
	printf("YES\n");
	REP(i, n) mini = min(ASS[i], mini);
	REP(i, n) printf("%d ", ASS[i]-mini+1);

	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sstream>
#include <iostream>
#include <math.h>
#include <time.h>
#include <unistd.h>
#include <algorithm>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <string>
#include <immintrin.h>
#ifndef ONLINE_JUDGE
	#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#else
	#define DEBUG(x) do {} while(0);
#endif

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define FOR(i, A, N) for(int (i) = (A); (i) < (N); (i)++)
#define REP(i, N) for(int (i) = 0; (i) < (N); (i)++)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#define ALIGN(x) __attribute__((aligned(x)))
using namespace std;
typedef long long ll;
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

int n,m;
vector<int> sons[2222];
int ASS[2222];
int P[2222];
int C[2222];
int known[2222];

void dfs(int curr, vector<int>& suball, int start = 1) {
	if(!start) suball.pb(ASS[curr]);
	for(int s : sons[curr]) {
		dfs(s, suball, 0);
	}
}
void dec(int curr, int val, int start = 1) {
	if(!start && ASS[curr] <= val) ASS[curr]--;
	for(int s : sons[curr]) {
		dec(s, val, 0);
	}
}
int cnt(int curr) {
	int ans = 1;
	for(int s : sons[curr])
		ans += cnt(s);
	return ans;
}
void inc(int curr, int val = 0, int start = 1) {
	int X = 0;
	if(!start) ASS[curr] += val;
	for(int s : sons[curr]) {
		if(start) {
			if(X) inc(s, X, 0);
			X += cnt(s);
		}
		else {
			inc(s, X, 0);
		}
	}
}

int main() {
	scanf("%d", &n);
	int root = 0;
	REP(i, n) {
		scanf("%d%d", P+i, C+i);
		P[i]--;
		if(P[i] == -1)
			root = i;
		else
			sons[P[i]].pb(i);
	}
	queue<int> Q;
	REP(i, n) {
		if(sons[i].size() == 0) {
			Q.push(i);
		}
	}
	int leafs = 1;
	int mini = 0;
	while(!Q.empty()) {
		int c = Q.front();
		Q.pop();
		if(sons[c].size() == 0) {
			if(C[c] != 0) {
				printf("NO\n");
				return 0;
			}
			ASS[c] = 1;
			leafs++;
			known[P[c]]++;
			if(known[P[c]] == sons[P[c]].size()) {
				Q.push(P[c]);
			}
		} else {
			vector<int> suball;
			inc(c);
			dfs(c, suball);
			sort(suball.begin(), suball.end());
			if(C[c] == 0) {
				ASS[c] = suball[0]-1;
			} else if(C[c] == suball.size()) {
				ASS[c] = suball[suball.size()-1]+1;
			} else if(C[c] < suball.size()) {
				dec(c, suball[C[c]-1]);
				ASS[c] = suball[C[c]-1];
			} else {
				printf("NO\n");
				return 0;
			}
			mini = min(mini, ASS[c]);

			if(P[c] != -1) {
				known[P[c]]++;
				if(known[P[c]] == sons[P[c]].size()) {
					Q.push(P[c]);
				}
			}
		}
	}
	printf("YES\n");
	REP(i, n) mini = min(ASS[i], mini);
	REP(i, n) printf("%d ", ASS[i]-mini+1);

	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sstream>
#include <iostream>
#include <math.h>
#include <time.h>
#include <unistd.h>
#include <cassert>
#include <algorithm>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <string>
#include <immintrin.h>
#ifndef ONLINE_JUDGE
	#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#else
	#define DEBUG(x) do {} while(0);
#endif

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define FOR(i, A, N) for(int (i) = (A); (i) < (N); (i)++)
#define REP(i, N) for(int (i) = 0; (i) < (N); (i)++)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#define ALIGN(x) __attribute__((aligned(x)))
using namespace std;
typedef long long ll;
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

int n,m;
vector<int> sons[2222];
int ASS[2222];
int P[2222];
int C[2222];
int known[2222];

void dfs(int curr, vector<int>& suball, int start = 1) {
	if(!start) suball.pb(ASS[curr]);
	for(int s : sons[curr]) {
		dfs(s, suball, 0);
	}
}
void dec(int curr, int val, int start = 1) {
	if(!start && ASS[curr] <= val) ASS[curr]--;
	for(int s : sons[curr]) {
		dec(s, val, 0);
	}
}
int cnt(int curr) {
	int ans = 1;
	for(int s : sons[curr])
		ans += cnt(s);
	return ans;
}
void inc(int curr, int val = 0, int start = 1) {
	int X = 0;
	if(!start) ASS[curr] += val;
	for(int s : sons[curr]) {
		if(start) {
			if(X) inc(s, X, 0);
			X += cnt(s);
		}
		else {
			inc(s, X, 0);
		}
	}
}
void fix(int curr, int val) {
	ASS[curr] -= val;
	for(int s : sons[curr]) {
		fix(s, val);
	}
}

int main() {
	scanf("%d", &n);
	int root = 0;
	REP(i, n) {
		scanf("%d%d", P+i, C+i);
		P[i]--;
		if(P[i] == -1)
			root = i;
		else
			sons[P[i]].pb(i);
	}
	queue<int> Q;
	REP(i, n) {
		if(sons[i].size() == 0) {
			Q.push(i);
		}
	}
	int leafs = 1;
	int mini = 0;
	while(!Q.empty()) {
		int c = Q.front();
		Q.pop();
		if(sons[c].size() == 0) {
			if(C[c]!= 0) {
				printf("NO\n");
				return 0;
			}
			ASS[c] = 0;
			known[P[c]]++;
			if(known[P[c]] == sons[P[c]].size()) {
				Q.push(P[c]);
			}
		} else {
			vector<int> suball;
			inc(c);
			dfs(c, suball);
			sort(suball.begin(), suball.end());
			int last = -1000000;
			for(int X : suball) {
				assert(X != last);
				last = X;
			}
			int fixval = suball[0];
			if(C[c] == 0) {
				ASS[c] = suball[0]-1;
				fixval--;
			} else if(C[c] == suball.size()) {
				ASS[c] = suball[suball.size()-1]+1;
			} else if(C[c] < suball.size()) {
				dec(c, suball[C[c]-1]);
				fixval--;
				ASS[c] = suball[C[c]-1];
			} else {
				printf("NO\n");
				return 0;
			}
			fix(c, fixval);
			mini = min(mini, ASS[c]);

			if(P[c] != -1) {
				known[P[c]]++;
				if(known[P[c]] == sons[P[c]].size()) {
					Q.push(P[c]);
				}
			}
		}
	}
	printf("YES\n");
	REP(i, n) mini = min(ASS[i], mini);
	REP(i, n) printf("%d ", ASS[i]-mini+1);

	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sstream>
#include <iostream>
#include <math.h>
#include <time.h>
#include <unistd.h>
#include <cassert>
#include <algorithm>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <string>
#include <immintrin.h>
#ifndef ONLINE_JUDGE
	#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#else
	#define DEBUG(x) do {} while(0);
#endif

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define FOR(i, A, N) for(int (i) = (A); (i) < (N); (i)++)
#define REP(i, N) for(int (i) = 0; (i) < (N); (i)++)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#define ALIGN(x) __attribute__((aligned(x)))
using namespace std;
typedef long long ll;
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

int n,m;
vector<int> sons[2222];
int ASS[2222];
int P[2222];
int C[2222];
int known[2222];

void dfs(int curr, vector<int>& suball, int start = 1) {
	if(!start) suball.pb(ASS[curr]);
	for(int s : sons[curr]) {
		dfs(s, suball, 0);
	}
}
void dec(int curr, int val, int start = 1) {
	if(!start && ASS[curr] <= val) ASS[curr]--;
	for(int s : sons[curr]) {
		dec(s, val, 0);
	}
}
int cnt(int curr) {
	int ans = 1;
	for(int s : sons[curr])
		ans += cnt(s);
	return ans;
}
void inc(int curr, int val = 0, int start = 1) {
	int X = 0;
	if(!start) ASS[curr] += val;
	for(int s : sons[curr]) {
		if(start) {
			if(X) inc(s, X, 0);
			X += cnt(s);
		}
		else {
			inc(s, X, 0);
		}
	}
}
void fix(int curr, int val) {
	ASS[curr] -= val;
	for(int s : sons[curr]) {
		fix(s, val);
	}
}

int main() {
	scanf("%d", &n);
	int root = 0;
	REP(i, n) {
		scanf("%d%d", P+i, C+i);
		P[i]--;
		if(P[i] == -1)
			root = i;
		else
			sons[P[i]].pb(i);
	}
	queue<int> Q;
	REP(i, n) {
		if(sons[i].size() == 0) {
			Q.push(i);
		}
	}
	int leafs = 1;
	int mini = 0;
	while(!Q.empty()) {
		int c = Q.front();
		Q.pop();
		if(sons[c].size() == 0) {
			if(C[c]!= 0) {
				printf("NO\n");
				return 0;
			}
			ASS[c] = 0;
			known[P[c]]++;
			if(known[P[c]] == sons[P[c]].size()) {
				Q.push(P[c]);
			}
		} else {
			vector<int> suball;
			inc(c);
			dfs(c, suball);
			sort(suball.begin(), suball.end());
			int last = -1000000;
			for(int X : suball) {
				assert(X != last);
				last = X;
			}
			int fixval = suball[0];
			if(C[c] == 0) {
				ASS[c] = suball[0]-1;
				fixval--;
			} else if(C[c] == suball.size()) {
				ASS[c] = suball[suball.size()-1]+1;
			} else if(C[c] < suball.size()) {
				dec(c, suball[C[c]-1]);
				ASS[c] = suball[C[c]-1];
			} else {
				printf("NO\n");
				return 0;
			}
			fix(c, fixval);
			mini = min(mini, ASS[c]);

			if(P[c] != -1) {
				known[P[c]]++;
				if(known[P[c]] == sons[P[c]].size()) {
					Q.push(P[c]);
				}
			}
		}
	}
	printf("YES\n");
	REP(i, n) mini = min(ASS[i], mini);
	REP(i, n) printf("%d ", ASS[i]-mini+1);

	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sstream>
#include <iostream>
#include <math.h>
#include <time.h>
#include <unistd.h>
#include <cassert>
#include <algorithm>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <string>
#include <immintrin.h>
#ifndef ONLINE_JUDGE
	#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#else
	#define DEBUG(x) do {} while(0);
#endif

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define FOR(i, A, N) for(int (i) = (A); (i) < (N); (i)++)
#define REP(i, N) for(int (i) = 0; (i) < (N); (i)++)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#define ALIGN(x) __attribute__((aligned(x)))
using namespace std;
typedef long long ll;
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

int n,m;
vector<int> sons[2222];
int ASS[2222];
int P[2222];
int C[2222];
int known[2222];

void dfs(int curr, vector<int>& suball, int start = 1) {
	if(!start) suball.pb(ASS[curr]);
	for(int s : sons[curr]) {
		dfs(s, suball, 0);
	}
}
void dec(int curr, int val, int start = 1) {
	if(!start && ASS[curr] <= val) ASS[curr]--;
	for(int s : sons[curr]) {
		dec(s, val, 0);
	}
}
int cnt(int curr) {
	int ans = 1;
	for(int s : sons[curr])
		ans += cnt(s);
	return ans;
}
void inc(int curr, int val = 0, int start = 1) {
	int X = 0;
	if(!start) {
		ASS[curr] += val;
	}
	for(int s : sons[curr]) {
		if(start) {
			if(X) inc(s, X, 0);
			X += cnt(s);
		}
		else {
			inc(s, val, 0);
		}
	}
}
void fix(int curr, int val) {
	ASS[curr] -= val;
	for(int s : sons[curr]) {
		fix(s, val);
	}
}

int main() {
	scanf("%d", &n);
	int root = 0;
	REP(i, n) {
		scanf("%d%d", P+i, C+i);
		P[i]--;
		if(P[i] == -1)
			root = i;
		else
			sons[P[i]].pb(i);
	}
	queue<int> Q;
	REP(i, n) {
		if(sons[i].size() == 0) {
			Q.push(i);
		}
	}
	int leafs = 1;
	int mini = 0;
	while(!Q.empty()) {
		int c = Q.front();
		Q.pop();
		if(sons[c].size() == 0) {
			if(C[c]!= 0) {
				printf("NO\n");
				return 0;
			}
			ASS[c] = 0;
			known[P[c]]++;
			if(known[P[c]] == sons[P[c]].size()) {
				Q.push(P[c]);
			}
		} else {
			vector<int> suball;
			inc(c);
			dfs(c, suball);
			sort(suball.begin(), suball.end());
			int last = -1000000;
			for(int X : suball) {
				assert(X != last);
				last = X;

			}
			int fixval = suball[0];
			if(C[c] == 0) {
				ASS[c] = suball[0]-1;
				fixval--;
			} else if(C[c] == suball.size()) {
				ASS[c] = suball[suball.size()-1]+1;
			} else if(C[c] < suball.size()) {
				dec(c, suball[C[c]-1]);
				fixval--;
				ASS[c] = suball[C[c]-1];
			} else {
				printf("NO\n");
				return 0;
			}
			fix(c, fixval);
			mini = min(mini, ASS[c]);

			if(P[c] != -1) {
				known[P[c]]++;
				if(known[P[c]] == sons[P[c]].size()) {
					Q.push(P[c]);
				}
			}
		}
	}
	printf("YES\n");
	REP(i, n) mini = min(ASS[i], mini);
	REP(i, n) printf("%d ", ASS[i]-mini+1);

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 2005;
int n, c[N], ans[N], root, siz[N];
bool exist = true;
vector<int> adj[N];

void dfs1(int v, int par){
    siz[v] = 1;
    for(auto x : adj[v]){
        if(par != x){
            dfs1(x, v);
            siz[v] += siz[x];
        }
    }
}

void update(int v, int par, int val, int num){
    vector<pair<int, int>> all;
    queue<pair<int, int>> q;
    q.push({v, par});
    while(!q.empty()){
        auto fr = q.front();
        all.push_back({ans[fr.first], fr.first});
        q.pop();

        for(auto x : adj[fr.first]){
            if(x != fr.second){
                q.push({x, fr.first});
            }
        }
    }
    sort(all.begin(), all.end());
    int cur = val;
    int i = 1;
    for(auto x : all){
        if(cur + i >= num){
            ans[x.second] = cur + 1 + i;
        } else {
            ans[x.second] = cur + i;
        }
        i++;
    }
}

void dfs2(int v, int par){
    if(c[v] >= siz[v]){
        exist = false;
    } else {
        if(siz[v] == 1){
            ans[v] = 1;
        } else {
            int num = c[v] + 1;
            ans[v] = num;
            int cur = 0;
            for(auto x : adj[v]){
                if(par != x){
                    dfs2(x, v);
                    if(num <= cur + siz[x]){
                        update(x, v, cur, num);
                        cur += siz[x] + 1;
                    } else {
                        update(x, v, cur, 1e9);
                        cur += siz[x];
                    }
                }
            }
        }
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> n;
    for(int i = 1; i <= n; i++){
        int a, b;
        cin >> a >> b;
        if(a == 0){
            root = i;
        } else {
            adj[a].push_back(i);
            adj[i].push_back(a);
        }
        c[i] = b;
    }

    dfs1(root, -1);
    dfs2(root, -1);

    if(exist){
        cout << "YES\n";
        for(int i = 1; i <= n; i++){
            cout << ans[i] << " ";
        }
    } else {
        cout << "NO\n";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 2005;
int n, c[N], ans[N], root, siz[N];
bool exist = true;
vector<int> adj[N];

void dfs1(int v, int par){
    siz[v] = 1;
    for(auto x : adj[v]){
        if(par != x){
            dfs1(x, v);
            siz[v] += siz[x];
        }
    }
}

void update1(int v, int par, int val){
    ans[v] += val;
    for(auto x : adj[v]){
        if(x != par){
            update1(x, v, val);
        }
    }
}

void update2(int v, int par, int val, int num){
    if(ans[v] + val >= num){
        ans[v] += val + 1;
    } else {
        ans[v] += val;
    }
    for(auto x : adj[v]){
        if(x != par){
            update2(x, v, val, num);
        }
    }
}

void dfs2(int v, int par){
    if(c[v] >= siz[v]){
        exist = false;
    } else {
        if(siz[v] == 1){
            ans[v] = 1;
        } else {
            int num = c[v] + 1;
            ans[v] = num;
            int cur = 0;
            for(auto x : adj[v]){
                if(par != x){
                    dfs2(x, v);
                    if(num <= cur + siz[x]){
                        update2(x, v, cur, num);
                        cur += siz[x] + 1;
                    } else {
                        update1(x, v, cur);
                        cur += siz[x];
                    }
                }
            }
        }
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> n;
    for(int i = 1; i <= n; i++){
        int a, b;
        cin >> a >> b;
        if(a == 0){
            root = i;
        } else {
            adj[a].push_back(i);
            adj[i].push_back(a);
        }
        c[i] = b;
    }

    dfs1(root, -1);
    dfs2(root, -1);

    if(exist){
        cout << "YES\n";
        for(int i = 1; i <= n; i++){
            cout << ans[i] << " ";
        }
    } else {
        cout << "NO\n";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 2005;
int n, c[N], ans[N], root, siz[N];
bool exist = true;
vector<int> adj[N];

void dfs1(int v, int par){
    siz[v] = 1;
    for(auto x : adj[v]){
        if(par != x){
            dfs1(x, v);
            siz[v] += siz[x];
        }
    }
}

void update1(int v, int par, int val){
    vector<pair<int, int>> all;

    queue<pair<int, int>> q;
    q.push({v, par});
    while(!q.empty()){
        auto fr = q.front();
        all.push_back({ans[fr.first], fr.first});
        q.pop();

        for(auto x : adj[fr.first]){
            if(x != fr.second){
                q.push({x, fr.first});
            }
        }
    }
    sort(all.begin(), all.end());
    int cur = val;
    int i = 1;
    for(auto x : all){
        ans[x.second] = cur + i;
        i++;
    }
}

void update2(int v, int par, int val, int num){

    vector<pair<int, int>> all;

    queue<pair<int, int>> q;
    q.push({v, par});
    while(!q.empty()){
        auto fr = q.front();
        all.push_back({ans[fr.first], fr.first});
        q.pop();

        for(auto x : adj[fr.first]){
            if(x != fr.second){
                q.push({x, fr.first});
            }
        }
    }
    sort(all.begin(), all.end());
    int cur = val;
    int i = 1;
    for(auto x : all){
        if(cur >= num){
            ans[x.second] = cur + 1 + i;
        } else {
            ans[x.second] = cur + i;
        }
        i++;
    }
}

void dfs2(int v, int par){
    if(c[v] >= siz[v]){
        exist = false;
    } else {
        if(siz[v] == 1){
            ans[v] = 1;
        } else {
            int num = c[v] + 1;
            ans[v] = num;
            int cur = 0;
            for(auto x : adj[v]){
                if(par != x){
                    dfs2(x, v);
                    if(num <= cur + siz[x]){
                        update2(x, v, cur, num);
                        cur += siz[x] + 1;
                    } else {
                        update1(x, v, cur);
                        cur += siz[x];
                    }
                }
            }
        }
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> n;
    for(int i = 1; i <= n; i++){
        int a, b;
        cin >> a >> b;
        if(a == 0){
            root = i;
        } else {
            adj[a].push_back(i);
            adj[i].push_back(a);
        }
        c[i] = b;
    }

    dfs1(root, -1);
    dfs2(root, -1);

    if(exist){
        cout << "YES\n";
        for(int i = 1; i <= n; i++){
            cout << ans[i] << " ";
        }
    } else {
        cout << "NO\n";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 2005;
int n, c[N], ans[N], root, siz[N];
bool exist = true;
vector<int> adj[N];

void dfs1(int v, int par){
    siz[v] = 1;
    for(auto x : adj[v]){
        if(par != x){
            dfs1(x, v);
            siz[v] += siz[x];
        }
    }
}

void update1(int v, int par, int val){
    vector<pair<int, int>> all;

    queue<pair<int, int>> q;
    q.push({v, par});
    while(!q.empty()){
        auto fr = q.front();
        all.push_back({ans[fr.first], fr.first});
        q.pop();

        for(auto x : adj[fr.first]){
            if(x != fr.second){
                q.push({x, fr.first});
            }
        }
    }
    sort(all.begin(), all.end());
    int cur = val;
    int i = 1;
    for(auto x : all){
        ans[x.second] = cur + i;
        i++;
    }
}

void update2(int v, int par, int val, int num){

    vector<pair<int, int>> all;

    queue<pair<int, int>> q;
    q.push({v, par});
    while(!q.empty()){
        auto fr = q.front();
        all.push_back({ans[fr.first], fr.first});
        q.pop();

        for(auto x : adj[fr.first]){
            if(x != fr.second){
                q.push({x, fr.first});
            }
        }
    }
    sort(all.begin(), all.end());
    int cur = val;
    int i = 1;
    for(auto x : all){
        if(cur + i >= num){
            ans[x.second] = cur + 1 + i;
        } else {
            ans[x.second] = cur + i;
        }
        i++;
    }
}

void dfs2(int v, int par){
    if(c[v] >= siz[v]){
        exist = false;
    } else {
        if(siz[v] == 1){
            ans[v] = 1;
        } else {
            int num = c[v] + 1;
            ans[v] = num;
            int cur = 0;
            for(auto x : adj[v]){
                if(par != x){
                    dfs2(x, v);
                    if(num <= cur + siz[x]){
                        update2(x, v, cur, num);
                        cur += siz[x] + 1;
                    } else {
                        update1(x, v, cur);
                        cur += siz[x];
                    }
                }
            }
        }
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> n;
    for(int i = 1; i <= n; i++){
        int a, b;
        cin >> a >> b;
        if(a == 0){
            root = i;
        } else {
            adj[a].push_back(i);
            adj[i].push_back(a);
        }
        c[i] = b;
    }

    dfs1(root, -1);
    dfs2(root, -1);

    if(exist){
        cout << "YES\n";
        for(int i = 1; i <= n; i++){
            cout << ans[i] << " ";
        }
    } else {
        cout << "NO\n";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 2005;
int n, c[N], ans[N], root, siz[N];
bool exist = true;
vector<int> adj[N];

void dfs1(int v, int par){
    siz[v] = 1;
    for(auto x : adj[v]){
        if(par != x){
            dfs1(x, v);
            siz[v] += siz[x];
        }
    }
}

void update1(int v, int par, int val){
    ans[v] += val;
    for(auto x : adj[v]){
        if(x != par){
            update1(x, v, val);
        }
    }
}

void update2(int v, int par, int val, int num){
    if(ans[v] + val >= num){
        ans[v] += val + 2;
    } else {
        ans[v] += val;
    }
    for(auto x : adj[v]){
        if(x != par){
            update2(x, v, val, num);
        }
    }
}

void dfs2(int v, int par){
    if(c[v] >= siz[v]){
        exist = false;
    } else {
        if(siz[v] == 1){
            ans[v] = 1;
        } else {
            int num = c[v] + 1;
            ans[v] = num;
            int cur = 0;
            for(auto x : adj[v]){
                if(par != x){
                    dfs2(x, v);
                    if(num <= cur + siz[x]){
                        update2(x, v, cur, num);
                        cur += siz[x] + 1;
                    } else {
                        update1(x, v, cur);
                        cur += siz[x];
                    }
                }
            }
        }
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> n;
    for(int i = 1; i <= n; i++){
        int a, b;
        cin >> a >> b;
        if(a == 0){
            root = i;
        } else {
            adj[a].push_back(i);
            adj[i].push_back(a);
        }
        c[i] = b;
    }

    dfs1(root, -1);
    dfs2(root, -1);

    if(exist){
        cout << "YES\n";
        for(int i = 1; i <= n; i++){
            cout << ans[i] << " ";
        }
    } else {
        cout << "NO\n";
    }
    return 0;
}


#include <bits/stdc++.h>
#define in(x) freopen(x,"r",stdin)
#define out(x) freopen(x,"w",stdout)
#define F first
#define S second
#define pb push_back
//#define M ll(1e9+7)
#define inf ll(2e9+7)
#define N ll(4*1e5)
#define sz(x) x.size()
#define mp make_pair
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
//#pragma GCC target("avx3")
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int n,v,c[N],nm,i,ans[N],root;
vector <int> g[N],p;

vector <int> dfs(int v)
{
   vector <int> V;
   for (auto u : g[v])
   {
      vector <int> v1=dfs(u);
      for (auto x : v1) V.pb(x);
   }
   if (V.size()<c[v]) {cout << "NO" << endl;exit(0);}
   if (g[v].size()==0) {V.pb(ans[v]);return V;}
   sort(V.begin(),V.end());
   if (c[v]!=0) ans[v]=V[c[v]-1]+1;else p.pb(v);
   V.pb(ans[v]);
   return V;
}

int main()
{
//    in("alarm.in");
//    out("alarm.out");
    ios_base::sync_with_stdio(false);
    iostream::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    for (i=1;i<=n;i++)
    {
       cin >> v >> c[i];
       if (v!=0) g[v].pb(i);
       else root = i;
    }
    nm=1;
    for (i=1;i<=n;i++) if (g[i].size()==0) ans[i]=nm,nm++;
    dfs(root);
    for (i=1;i<=n;i++) if (g[i].size()==0) p.pb(i);
    nm=n;
    for (i=0;i<p.size();i++) ans[p[i]]=nm--;
    cout << "YES" << endl;
    for (i=1;i<=n;i++) cout << ans[i] << " ";
}


#include <bits/stdc++.h>
#define in(x) freopen(x,"r",stdin)
#define out(x) freopen(x,"w",stdout)
#define F first
#define S second
#define pb push_back
//#define M ll(1e9+7)
#define inf ll(2e9+7)
#define N ll(4*1e5)
#define sz(x) x.size()
#define mp make_pair
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
//#pragma GCC target("avx3")
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int n,v,c[N],nm,i,ans[N],root;
vector <int> g[N];

bool cmp(int x,int y) {return ans[x]<ans[y];}

vector <int> dfs(int v)
{
   vector <int> V;
   for (auto u : g[v])
   {
      vector <int> v1=dfs(u);
      for (auto x : v1) V.pb(x);
   }
   if (V.size()<c[v]) {cout << "NO" << endl;exit(0);}
   if (g[v].size()==0) {V.pb(v);return V;}
   sort(V.begin(),V.end(),cmp);
   ans[v]=c[v] ? ans[V[c[v]-1]]+1 : 1;
   for (int p = c[v]; p < V.size(); p++) ans[V[p]]+=p-c[v]+2,ans[V[p]]*=2;
   V.pb(v);
   return V;
}

int main()
{
//    in("alarm.in");
//    out("alarm.out");
    ios_base::sync_with_stdio(false);
    iostream::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    for (i=1;i<=n;i++)
    {
       cin >> v >> c[i];
       if (v!=0) g[v].pb(i);
       else root = i;
    }
    nm=1;
    for (i=1;i<=n;i++) if (g[i].size()==0) ans[i]=nm,nm++;
    dfs(root);
    cout << "YES" << endl;
    for (i=1;i<=n;i++) cout << ans[i] << " ";
}


#include <bits/stdc++.h>
#define in(x) freopen(x,"r",stdin)
#define out(x) freopen(x,"w",stdout)
#define F first
#define S second
#define pb push_back
//#define M ll(1e9+7)
#define inf ll(2e9+7)
#define N ll(4*1e5)
#define sz(x) x.size()
#define mp make_pair
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
//#pragma GCC target("avx3")
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int n,v,c[N],nm,i,ans[N],root;
vector <int> g[N];

bool cmp(int x,int y) {return ans[x]<ans[y];}

vector <int> dfs(int v)
{
   vector <int> V;
   for (auto u : g[v])
   {
      vector <int> v1=dfs(u);
      for (auto x : v1) V.pb(x);
   }
   if (V.size()<c[v]) {cout << "NO" << endl;exit(0);}
   if (g[v].size()==0) {V.pb(v);return V;}
   sort(V.begin(),V.end(),cmp);
   for (int p = c[v]; p < V.size(); p++) ans[V[p]]++;
   ans[v]=c[v] ? ans[V[c[v]]] : 1;
   V.pb(v);
   return V;
}

int main()
{
//    in("alarm.in");
//    out("alarm.out");
    ios_base::sync_with_stdio(false);
    iostream::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    for (i=1;i<=n;i++)
    {
       cin >> v >> c[i];
       if (v!=0) g[v].pb(i);
       else root = i;
    }
    nm=1;
    for (i=1;i<=n;i++) if (g[i].size()==0) ans[i]=nm,nm++;
    dfs(root);
    cout << "YES" << endl;
    for (i=1;i<=n;i++) cout << ans[i] << " ";
}


#include <bits/stdc++.h>
#define in(x) freopen(x,"r",stdin)
#define out(x) freopen(x,"w",stdout)
#define F first
#define S second
#define pb push_back
//#define M ll(1e9+7)
#define inf ll(2e9+7)
#define N ll(4*1e5)
#define sz(x) x.size()
#define mp make_pair
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
//#pragma GCC target("avx3")
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int n,v,c[N],nm,i,ans[N],root;
vector <int> g[N];

bool cmp(int x,int y) {return ans[x]<ans[y];}

vector <int> dfs(int v)
{
   vector <int> V;
   for (auto u : g[v])
   {
      vector <int> v1=dfs(u);
      for (auto x : v1) V.pb(x);
   }
   if (V.size()<c[v]) {cout << "NO" << endl;exit(0);}
   if (g[v].size()==0) {V.pb(v);return V;}
   sort(V.begin(),V.end(),cmp);
   ans[v]=c[v] ? ans[V[c[v]-1]]+1 : 1;
   for (int p = c[v]; p < V.size(); p++) ans[V[p]]=min(ans[V[p]]+p-c[v]+1,(c[v]?ans[V[c[v]-1]]:1) + p-c[v]+1);
   V.pb(v);
   return V;
}

int main()
{
//    in("alarm.in");
//    out("alarm.out");
    ios_base::sync_with_stdio(false);
    iostream::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    for (i=1;i<=n;i++)
    {
       cin >> v >> c[i];
       if (v!=0) g[v].pb(i);
       else root = i;
    }
    nm=1;
    for (i=1;i<=n;i++) if (g[i].size()==0) ans[i]=nm,nm++;
    dfs(root);
    cout << "YES" << endl;
    for (i=1;i<=n;i++) cout << ans[i] << " ";
}


#include <bits/stdc++.h>
#define in(x) freopen(x,"r",stdin)
#define out(x) freopen(x,"w",stdout)
#define F first
#define S second
#define pb push_back
//#define M ll(1e9+7)
#define inf ll(2e9+7)
#define N ll(4*1e5)
#define sz(x) x.size()
#define mp make_pair
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
//#pragma GCC target("avx3")
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int n,v,c[N],nm,i,ans[N],root;
vector <int> g[N];

vector <int> dfs(int v)
{
   vector <int> V;
   for (auto u : g[v])
   {
      vector <int> v1=dfs(u);
      for (auto x : v1) V.pb(x);
   }
   if (g[v].size()==0) {V.pb(ans[v]);return V;}
   if (V.size()<c[v]) {cout << "NO" << endl;exit(0);}
   sort(V.begin(),V.end());
   ans[v]=V[c[v]-1]+1;
   V.pb(ans[v]);
   return V;
}

int main()
{
//    in("alarm.in");
//    out("alarm.out");
    ios_base::sync_with_stdio(false);
    iostream::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    for (i=1;i<=n;i++)
    {
       cin >> v >> c[i];
       if (v!=0) g[v].pb(i);
       else root = i;
    }
    nm=1;
    for (i=1;i<=n;i++) if (g[i].size()==0) ans[i]=nm,nm++;
    dfs(root);
    cout << "YES" << endl;
    for (i=1;i<=n;i++) cout << ans[i] << " ";
}


#include <bits/stdc++.h>
#define in(x) freopen(x,"r",stdin)
#define out(x) freopen(x,"w",stdout)
#define F first
#define S second
#define pb push_back
//#define M ll(1e9+7)
#define inf ll(2e9+7)
#define N ll(4*1e5)
#define sz(x) x.size()
#define mp make_pair
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
//#pragma GCC target("avx3")
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

ll n,v,c[N],nm,i,ans[N],root;
vector <int> g[N];

bool cmp(int x,int y) {return ans[x]<ans[y];}

vector <int> dfs(int v)
{
   vector <int> V;
   for (auto u : g[v])
   {
      vector <int> v1=dfs(u);
      for (auto x : v1) V.pb(x);
   }
   if (V.size()<c[v]) {cout << "NO" << endl;exit(0);}
   if (g[v].size()==0) {V.pb(v);return V;}
   sort(V.begin(),V.end(),cmp);
   ans[v]=c[v] ? ans[V[c[v]-1]]+1 : 1;
   for (int p = c[v]; p < V.size(); p++) ans[V[p]]+=p-c[v]+2,ans[V[p]]*=2;
   V.pb(v);
   return V;
}

int main()
{
//    in("alarm.in");
//    out("alarm.out");
    ios_base::sync_with_stdio(false);
    iostream::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    for (i=1;i<=n;i++)
    {
       cin >> v >> c[i];
       if (v!=0) g[v].pb(i);
       else root = i;
    }
    nm=1;
    for (i=1;i<=n;i++) if (g[i].size()==0) ans[i]=nm,nm++;
    dfs(root);
    cout << "YES" << endl;
    for (i=1;i<=n;i++) cout << ans[i] << " ";
}


#include <bits/stdc++.h>
#define in(x) freopen(x,"r",stdin)
#define out(x) freopen(x,"w",stdout)
#define F first
#define S second
#define pb push_back
//#define M ll(1e9+7)
#define inf ll(2e9+7)
#define N ll(4*1e5)
#define sz(x) x.size()
#define mp make_pair
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
//#pragma GCC target("avx3")
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int n,v,c[N],nm,i,ans[N],root;
vector <int> g[N];

bool cmp(int x,int y) {return ans[x]<ans[y];}

vector <int> dfs(int v)
{
   vector <int> V;
   for (auto u : g[v])
   {
      vector <int> v1=dfs(u);
      for (auto x : v1) V.pb(x);
   }
   if (V.size()<c[v]) {cout << "NO" << endl;exit(0);}
   if (g[v].size()==0) {V.pb(v);return V;}
   sort(V.begin(),V.end(),cmp);
   ans[v]=c[v] ? ans[V[c[v]-1]]+1 : 1;
   for (int p = c[v]; p < V.size(); p++) ans[V[p]]=ans[V[c[v]-1]]+p-c[v]+1;
   V.pb(v);
   return V;
}

int main()
{
//    in("alarm.in");
//    out("alarm.out");
    ios_base::sync_with_stdio(false);
    iostream::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    for (i=1;i<=n;i++)
    {
       cin >> v >> c[i];
       if (v!=0) g[v].pb(i);
       else root = i;
    }
    nm=1;
    for (i=1;i<=n;i++) if (g[i].size()==0) ans[i]=nm,nm++;
    dfs(root);
    cout << "YES" << endl;
    for (i=1;i<=n;i++) cout << ans[i] << " ";
}


#include <bits/stdc++.h>
#define in(x) freopen(x,"r",stdin)
#define out(x) freopen(x,"w",stdout)
#define F first
#define S second
#define pb push_back
//#define M ll(1e9+7)
#define inf ll(2e9+7)
#define N ll(4*1e5)
#define sz(x) x.size()
#define mp make_pair
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
//#pragma GCC target("avx3")
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int n,v,c[N],nm,i,ans[N],root;
vector <int> g[N];

bool cmp(int x,int y) {return ans[x]<ans[y];}

vector <int> dfs(int v)
{
   vector <int> V;
   for (auto u : g[v])
   {
      vector <int> v1=dfs(u);
      for (auto x : v1) V.pb(x);
   }
   if (V.size()<c[v]) {cout << "NO" << endl;exit(0);}
   if (g[v].size()==0) {V.pb(v);return V;}
   sort(V.begin(),V.end(),cmp);
   ans[v]=c[v] ? ans[V[c[v]-1]]+1 : 1;
   for (int p = c[v]; p < V.size(); p++) ans[V[p]]+=p-c[v]+1;
   V.pb(v);
   return V;
}

int main()
{
//    in("alarm.in");
//    out("alarm.out");
    ios_base::sync_with_stdio(false);
    iostream::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    for (i=1;i<=n;i++)
    {
       cin >> v >> c[i];
       if (v!=0) g[v].pb(i);
       else root = i;
    }
    nm=1;
    for (i=1;i<=n;i++) if (g[i].size()==0) ans[i]=nm,nm++;
    dfs(root);
    cout << "YES" << endl;
    for (i=1;i<=n;i++) cout << ans[i] << " ";
}


#include <bits/stdc++.h>
#define in(x) freopen(x,"r",stdin)
#define out(x) freopen(x,"w",stdout)
#define F first
#define S second
#define pb push_back
//#define M ll(1e9+7)
#define inf ll(2e9+7)
#define N ll(4*1e5)
#define sz(x) x.size()
#define mp make_pair
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
//#pragma GCC target("avx3")
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int n,v,c[N],nm,i,ans[N],root;
vector <int> g[N];

vector <int> dfs(int v)
{
   vector <int> V;
   for (auto u : g[v])
   {
      vector <int> v1=dfs(u);
      for (auto x : v1) V.pb(x);
   }
   if (V.size()<c[v]) {cout << "NO" << endl;exit(0);}
   if (g[v].size()==0) {V.pb(ans[v]);return V;}
   sort(V.begin(),V.end());
   if (c[v]==0) ans[v]=1;else ans[v]=V[c[v]-1]+1;
   V.pb(ans[v]);
   return V;
}

int main()
{
//    in("alarm.in");
//    out("alarm.out");
    ios_base::sync_with_stdio(false);
    iostream::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    for (i=1;i<=n;i++)
    {
       cin >> v >> c[i];
       if (v!=0) g[v].pb(i);
       else root = i;
    }
    nm=1;
    for (i=1;i<=n;i++) if (g[i].size()==0) ans[i]=nm,nm++;
    dfs(root);
    cout << "YES" << endl;
    for (i=1;i<=n;i++) cout << ans[i] << " ";
}


#include <bits/stdc++.h>
#define in(x) freopen(x,"r",stdin)
#define out(x) freopen(x,"w",stdout)
#define F first
#define S second
#define pb push_back
//#define M ll(1e9+7)
#define inf ll(2e9+7)
#define N ll(4*1e5)
#define sz(x) x.size()
#define mp make_pair
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
//#pragma GCC target("avx3")
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int n,v,c[N],nm,i,ans[N],root;
vector <int> g[N];

vector <int> dfs(int v)
{
   vector <int> V;
   for (auto u : g[v])
   {
      vector <int> v1=dfs(u);
      for (auto x : v1) V.pb(x);
   }
   if (V.size()<c[v]) {cout << "NO" << endl;exit(0);}
   if (g[v].size()==0) {V.pb(ans[v]);return V;}
   sort(V.begin(),V.end());
   if (c[v]!=0) ans[v]=V[c[v]-1]+1;
   V.pb(ans[v]);
   return V;
}

int main()
{
//    in("alarm.in");
//    out("alarm.out");
    ios_base::sync_with_stdio(false);
    iostream::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    for (i=1;i<=n;i++)
    {
       cin >> v >> c[i];
       if (v!=0) g[v].pb(i);
       else root = i;
    }
    nm=1;
    for (i=1;i<=n;i++) if (g[i].size()==0) ans[i]=nm,nm++;
    dfs(root);
    nm=n;
    for (i=1;i<=n;i++) if (ans[i]==0) ans[i]=nm++;
    cout << "YES" << endl;
    for (i=1;i<=n;i++) cout << ans[i] << " ";
}


#include <bits/stdc++.h>
#define in(x) freopen(x,"r",stdin)
#define out(x) freopen(x,"w",stdout)
#define F first
#define S second
#define pb push_back
//#define M ll(1e9+7)
#define inf ll(2e9+7)
#define N ll(4*1e5)
#define sz(x) x.size()
#define mp make_pair
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
//#pragma GCC target("avx3")
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int n,v,c[N],nm,i,ans[N],root;
vector <int> g[N];

bool cmp(int x,int y) {return ans[x]<ans[y];}

vector <int> dfs(int v)
{
   vector <int> V;
   for (auto u : g[v])
   {
      vector <int> v1=dfs(u);
      for (auto x : v1) V.pb(x);
   }
   if (V.size()<c[v]) {cout << "NO" << endl;exit(0);}
   if (g[v].size()==0) {V.pb(v);return V;}
   sort(V.begin(),V.end(),cmp);
   ans[v]=c[v] ? ans[V[c[v]-1]]+1 : 1;
   for (int p = c[v]; p < V.size(); p++) ans[V[p]]=ans[c[v]-1]+p-c[v]+1;
   V.pb(v);
   return V;
}

int main()
{
//    in("alarm.in");
//    out("alarm.out");
    ios_base::sync_with_stdio(false);
    iostream::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    for (i=1;i<=n;i++)
    {
       cin >> v >> c[i];
       if (v!=0) g[v].pb(i);
       else root = i;
    }
    for (i=1;i<=n;i++) if (g[i].size()==0) ans[i]=1;
    dfs(root);
    cout << "YES" << endl;
    for (i=1;i<=n;i++) cout << ans[i] << " ";
}


#include <bits/stdc++.h>
#define in(x) freopen(x,"r",stdin)
#define out(x) freopen(x,"w",stdout)
#define F first
#define S second
#define pb push_back
//#define M ll(1e9+7)
#define inf ll(2e9+7)
#define N ll(4*1e5)
#define sz(x) x.size()
#define mp make_pair
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
//#pragma GCC target("avx3")
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int n,v,c[N],nm,i,ans[N],root;
vector <int> g[N];

bool cmp(int x,int y) {return ans[x]<ans[y];}

vector <int> dfs(int v)
{
   vector <int> V;
   for (auto u : g[v])
   {
      vector <int> v1=dfs(u);
      for (auto x : v1) V.pb(x);
   }
   if (V.size()<c[v]) {cout << "NO" << endl;exit(0);}
   if (g[v].size()==0) {V.pb(v);return V;}
   sort(V.begin(),V.end(),cmp);
   ans[v]=c[v] ? ans[V[c[v]]] : 1;
   for (int p = c[v]; p < V.size(); p++) ans[V[p]]++;
   V.pb(v);
   return V;
}

int main()
{
//    in("alarm.in");
//    out("alarm.out");
    ios_base::sync_with_stdio(false);
    iostream::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    for (i=1;i<=n;i++)
    {
       cin >> v >> c[i];
       if (v!=0) g[v].pb(i);
       else root = i;
    }
    nm=1;
    for (i=1;i<=n;i++) if (g[i].size()==0) ans[i]=nm,nm++;
    dfs(root);
    cout << "YES" << endl;
    for (i=1;i<=n;i++) cout << ans[i] << " ";
}


#include <bits/stdc++.h>
#define in(x) freopen(x,"r",stdin)
#define out(x) freopen(x,"w",stdout)
#define F first
#define S second
#define pb push_back
//#define M ll(1e9+7)
#define inf ll(2e9+7)
#define N ll(4*1e5)
#define sz(x) x.size()
#define mp make_pair
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
//#pragma GCC target("avx3")
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int n,v,c[N],nm,i,ans[N],root;
vector <int> g[N];

bool cmp(int x,int y) {return ans[x]<ans[y];}

vector <int> dfs(int v)
{
   vector <int> V;
   for (auto u : g[v])
   {
      vector <int> v1=dfs(u);
      for (auto x : v1) V.pb(x);
   }
   if (V.size()<c[v]) {cout << "NO" << endl;exit(0);}
   if (g[v].size()==0) {V.pb(v);return V;}
   sort(V.begin(),V.end(),cmp);
   ans[v]=c[v] ? ans[V[c[v]-1]]+1 : 1;
   for (int p = c[v]; p < V.size(); p++) ans[V[p]]+=(c[v]?ans[V[c[v]-1]]:1);
   V.pb(v);
   return V;
}

int main()
{
//    in("alarm.in");
//    out("alarm.out");
    ios_base::sync_with_stdio(false);
    iostream::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    for (i=1;i<=n;i++)
    {
       cin >> v >> c[i];
       if (v!=0) g[v].pb(i);
       else root = i;
    }
    nm=1;
    for (i=1;i<=n;i++) if (g[i].size()==0) ans[i]=nm,nm++;
    dfs(root);
    cout << "YES" << endl;
    for (i=1;i<=n;i++) cout << ans[i] << " ";
}


#include <bits/stdc++.h>
#define in(x) freopen(x,"r",stdin)
#define out(x) freopen(x,"w",stdout)
#define F first
#define S second
#define pb push_back
//#define M ll(1e9+7)
#define inf ll(2e9+7)
#define N ll(4*1e5)
#define sz(x) x.size()
#define mp make_pair
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
//#pragma GCC target("avx3")
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

ll n,v,c[N],nm,i,ans[N],root;
vector <int> g[N];

bool cmp(int x,int y) {return ans[x]<ans[y];}

vector <int> dfs(int v)
{
   vector <int> V;
   for (auto u : g[v])
   {
      vector <int> v1=dfs(u);
      for (auto x : v1) V.pb(x);
   }
   if (V.size()<c[v]) {cout << "NO" << endl;exit(0);}
   if (g[v].size()==0) {V.pb(v);return V;}
   sort(V.begin(),V.end(),cmp);
   ans[v]=c[v] ? ans[V[c[v]-1]]+1 : 1;
   for (int p = c[v]; p < V.size(); p++) ans[V[p]]=ans[v]+p-c[v]+2;
   V.pb(v);
   return V;
}

int main()
{
//    in("alarm.in");
//    out("alarm.out");
    ios_base::sync_with_stdio(false);
    iostream::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    for (i=1;i<=n;i++)
    {
       cin >> v >> c[i];
       if (v!=0) g[v].pb(i);
       else root = i;
    }
    nm=1;
    for (i=1;i<=n;i++) if (g[i].size()==0) ans[i]=nm,nm++;
    dfs(root);
    cout << "YES" << endl;
    for (i=1;i<=n;i++) cout << ans[i] << " ";
}


#include <bits/stdc++.h>
#define in(x) freopen(x,"r",stdin)
#define out(x) freopen(x,"w",stdout)
#define F first
#define S second
#define pb push_back
//#define M ll(1e9+7)
#define inf ll(2e9+7)
#define N ll(4*1e5)
#define sz(x) x.size()
#define mp make_pair
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
//#pragma GCC target("avx3")
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int n,v,c[N],nm,i,ans[N],root;
vector <int> g[N];

bool cmp(int x,int y) {return ans[x]<ans[y];}

vector <int> dfs(int v)
{
   vector <int> V;
   for (auto u : g[v])
   {
      vector <int> v1=dfs(u);
      for (auto x : v1) V.pb(x);
   }
   if (V.size()<c[v]) {cout << "NO" << endl;exit(0);}
   if (g[v].size()==0) {V.pb(v);return V;}
   sort(V.begin(),V.end(),cmp);
   ans[v]=c[v] ? ans[V[c[v]-1]]+1 : 1;
   for (int p = c[v]; p < V.size(); p++) ans[V[p]]=(c[v]?ans[V[c[v]-1]]:1)+p-c[v]+1;
   V.pb(v);
   return V;
}

int main()
{
//    in("alarm.in");
//    out("alarm.out");
    ios_base::sync_with_stdio(false);
    iostream::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    for (i=1;i<=n;i++)
    {
       cin >> v >> c[i];
       if (v!=0) g[v].pb(i);
       else root = i;
    }
    nm=1;
    for (i=1;i<=n;i++) if (g[i].size()==0) ans[i]=nm,nm++;
    dfs(root);
    cout << "YES" << endl;
    for (i=1;i<=n;i++) cout << ans[i] << " ";
}


#include <bits/stdc++.h>
#define in(x) freopen(x,"r",stdin)
#define out(x) freopen(x,"w",stdout)
#define F first
#define S second
#define pb push_back
//#define M ll(1e9+7)
#define inf ll(2e9+7)
#define N ll(4*1e5)
#define sz(x) x.size()
#define mp make_pair
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
//#pragma GCC target("avx3")
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int n,v,c[N],nm,i,ans[N],root;
vector <int> g[N];

vector <int> dfs(int v)
{
   vector <int> V;
   for (auto u : g[v])
   {
      vector <int> v1=dfs(u);
      for (auto x : v1) V.pb(x);
   }
   if (g[v].size()==0) {V.pb(ans[v]);return V;}
   if (V.size()<c[v]) {cout << "NO" << endl;exit(0);}
   sort(V.begin(),V.end());
   if (c[v]==0) ans[v]=1;else ans[v]=V[c[v]-1]+1;
   V.pb(ans[v]);
   return V;
}

int main()
{
//    in("alarm.in");
//    out("alarm.out");
    ios_base::sync_with_stdio(false);
    iostream::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    for (i=1;i<=n;i++)
    {
       cin >> v >> c[i];
       if (v!=0) g[v].pb(i);
       else root = i;
    }
    nm=1;
    for (i=1;i<=n;i++) if (g[i].size()==0) ans[i]=nm,nm++;
    dfs(root);
    cout << "YES" << endl;
    for (i=1;i<=n;i++) cout << ans[i] << " ";
}


#include <bits/stdc++.h>
#define in(x) freopen(x,"r",stdin)
#define out(x) freopen(x,"w",stdout)
#define F first
#define S second
#define pb push_back
//#define M ll(1e9+7)
#define inf ll(2e9+7)
#define N ll(4*1e5)
#define sz(x) x.size()
#define mp make_pair
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
//#pragma GCC target("avx3")
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int n,v,c[N],nm,i,ans[N],root;
vector <int> g[N];

vector <pair <int, int> > dfs(int v)
{
   vector <pair <int, int> > V;
   for (auto u : g[v])
   {
      vector <pair <int, int> > v1=dfs(u);
      for (auto x : v1) V.pb(x);
   }
   if (V.size()<c[v]) {cout << "NO" << endl;exit(0);}
   if (g[v].size()==0) {V.pb({ans[v],v});return V;}
   sort(V.begin(),V.end());
   ans[v]=c[v] ? V[c[v]-1].F+1 : 1;
   for (int p = c[v]; p < V.size(); p++) ans[V[p].S]++,V[p].F=ans[V[p].S];
   V.pb({ans[v],v});
   return V;
}

int main()
{
//    in("alarm.in");
//    out("alarm.out");
    ios_base::sync_with_stdio(false);
    iostream::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    for (i=1;i<=n;i++)
    {
       cin >> v >> c[i];
       if (v!=0) g[v].pb(i);
       else root = i;
    }
    nm=1;
    for (i=1;i<=n;i++) if (g[i].size()==0) ans[i]=nm,nm++;
    dfs(root);
    cout << "YES" << endl;
    for (i=1;i<=n;i++) cout << ans[i] << " ";
}


#include <bits/stdc++.h>
#define in(x) freopen(x,"r",stdin)
#define out(x) freopen(x,"w",stdout)
#define F first
#define S second
#define pb push_back
//#define M ll(1e9+7)
#define inf ll(2e9+7)
#define N ll(4*1e5)
#define sz(x) x.size()
#define mp make_pair
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
//#pragma GCC target("avx3")
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int n,v,c[N],nm,i,ans[N],root;
vector <int> g[N];

vector <int> dfs(int v)
{
   vector <int> V;
   for (auto u : g[v])
   {
      vector <int> v1=dfs(u);
      for (auto x : v1) V.pb(x);
   }
   if (V.size()<c[v]) {cout << "NO" << endl;exit(0);}
   if (g[v].size()==0) {V.pb(ans[v]);return V;}
   sort(V.begin(),V.end());
   ans[v]=c[v] ? V[c[v]-1]+1 : 1;
   for (int p = c[v]; p < V.size(); p++) ans[V[p]]++;
   V.pb(ans[v]);
   return V;
}

int main()
{
//    in("alarm.in");
//    out("alarm.out");
    ios_base::sync_with_stdio(false);
    iostream::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    for (i=1;i<=n;i++)
    {
       cin >> v >> c[i];
       if (v!=0) g[v].pb(i);
       else root = i;
    }
    nm=1;
    for (i=1;i<=n;i++) if (g[i].size()==0) ans[i]=nm,nm++;
    dfs(root);
    cout << "YES" << endl;
    for (i=1;i<=n;i++) cout << ans[i] << " ";
}


#include <bits/stdc++.h>
#define in(x) freopen(x,"r",stdin)
#define out(x) freopen(x,"w",stdout)
#define F first
#define S second
#define pb push_back
//#define M ll(1e9+7)
#define inf ll(2e9+7)
#define N ll(4*1e5)
#define sz(x) x.size()
#define mp make_pair
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
//#pragma GCC target("avx3")
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int n,v,c[N],nm,i,ans[N],root;
vector <int> g[N];

vector <int> dfs(int v)
{
   vector <int> V;
   for (auto u : g[v])
   {
      vector <int> v1=dfs(u);
      for (auto x : v1) V.pb(x);
   }
   if (V.size()<c[v]) {cout << "NO" << endl;exit(0);}
   if (g[v].size()==0) {V.pb(ans[v]);return V;}
   sort(V.begin(),V.end());
   if (c[v]!=0) ans[v]=V[c[v]-1]+1;else ans[v]=V[0];
   V.pb(ans[v]);
   return V;
}

int main()
{
//    in("alarm.in");
//    out("alarm.out");
    ios_base::sync_with_stdio(false);
    iostream::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    for (i=1;i<=n;i++)
    {
       cin >> v >> c[i];
       if (v!=0) g[v].pb(i);
       else root = i;
    }
    nm=1;
    for (i=1;i<=n;i++) if (g[i].size()==0) ans[i]=nm,nm++;
    dfs(root);
    cout << "YES" << endl;
    for (i=1;i<=n;i++) cout << ans[i] << " ";
}


#include <bits/stdc++.h>
#define in(x) freopen(x,"r",stdin)
#define out(x) freopen(x,"w",stdout)
#define F first
#define S second
#define pb push_back
//#define M ll(1e9+7)
#define inf ll(2e9+7)
#define N ll(4*1e5)
#define sz(x) x.size()
#define mp make_pair
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
//#pragma GCC target("avx3")
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int n,v,c[N],nm,i,ans[N],root;
vector <int> g[N];

bool cmp(int x,int y) {return ans[x]<ans[y];}

vector <int> dfs(int v)
{
   vector <int> V;
   for (auto u : g[v])
   {
      vector <int> v1=dfs(u);
      for (auto x : v1) V.pb(x);
   }
   if (V.size()<c[v]) {cout << "NO" << endl;exit(0);}
   if (g[v].size()==0) {V.pb(v);return V;}
   sort(V.begin(),V.end(),cmp);
   ans[v]=c[v] ? ans[V[c[v]-1]]+1 : 1;
   for (int p = c[v]; p < V.size(); p++) ans[V[p]]++;
   V.pb(v);
   return V;
}

int main()
{
//    in("alarm.in");
//    out("alarm.out");
    ios_base::sync_with_stdio(false);
    iostream::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    for (i=1;i<=n;i++)
    {
       cin >> v >> c[i];
       if (v!=0) g[v].pb(i);
       else root = i;
    }
    for (i=1;i<=n;i++) if (g[i].size()==0) ans[i]=1;
    dfs(root);
    cout << "YES" << endl;
    for (i=1;i<=n;i++) cout << ans[i] << " ";
}


#include <bits/stdc++.h>
#define in(x) freopen(x,"r",stdin)
#define out(x) freopen(x,"w",stdout)
#define F first
#define S second
#define pb push_back
//#define M ll(1e9+7)
#define inf ll(2e9+7)
#define N ll(4*1e5)
#define sz(x) x.size()
#define mp make_pair
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
//#pragma GCC target("avx3")
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int n,v,c[N],nm,i,ans[N],root;
vector <int> g[N];

bool cmp(int x,int y) {return ans[x]<ans[y];}

vector <int> dfs(int v)
{
   vector <int> V;
   for (auto u : g[v])
   {
      vector <int> v1=dfs(u);
      for (auto x : v1) V.pb(x);
   }
   if (V.size()<c[v]) {cout << "NO" << endl;exit(0);}
   if (g[v].size()==0) {V.pb(v);return V;}
   sort(V.begin(),V.end(),cmp);
   ans[v]=c[v] ? ans[V[c[v]-1]]+1 : 1;
   for (int p = c[v]; p < V.size(); p++) ans[V[p]]++;
   V.pb(v);
   return V;
}

int main()
{
//    in("alarm.in");
//    out("alarm.out");
    ios_base::sync_with_stdio(false);
    iostream::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    for (i=1;i<=n;i++)
    {
       cin >> v >> c[i];
       if (v!=0) g[v].pb(i);
       else root = i;
    }
    nm=1;
    for (i=1;i<=n;i++) if (g[i].size()==0) ans[i]=nm,nm++;
    dfs(root);
    cout << "YES" << endl;
    for (i=1;i<=n;i++) cout << ans[i] << " ";
}


#include <bits/stdc++.h>
#define in(x) freopen(x,"r",stdin)
#define out(x) freopen(x,"w",stdout)
#define F first
#define S second
#define pb push_back
//#define M ll(1e9+7)
#define inf ll(2e9+7)
#define N ll(4*1e5)
#define sz(x) x.size()
#define mp make_pair
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
//#pragma GCC target("avx3")
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int n,v,c[N],nm,i,ans[N],root;
vector <int> g[N];

bool cmp(int x,int y) {return ans[x]<ans[y];}

vector <int> dfs(int v)
{
   vector <int> V;
   for (auto u : g[v])
   {
      vector <int> v1=dfs(u);
      for (auto x : v1) V.pb(x);
   }
   if (V.size()<c[v]) {cout << "NO" << endl;exit(0);}
   if (g[v].size()==0) {V.pb(v);return V;}
   sort(V.begin(),V.end(),cmp);
   ans[v]=c[v] ? ans[V[c[v]-1]]+1 : 1;
   if (c[v]<V.size() && V[c[v]]<V[c[v]-1]) for (int p = c[v]; p < V.size(); p++) ans[V[p]]=(c[v]?ans[V[c[v]-1]]:1)+p-c[v]+1;
   else for (int p = c[v]; p < V.size(); p++) ans[V[p]]++;
   V.pb(v);
   return V;
}

int main()
{
//    in("alarm.in");
//    out("alarm.out");
    ios_base::sync_with_stdio(false);
    iostream::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    for (i=1;i<=n;i++)
    {
       cin >> v >> c[i];
       if (v!=0) g[v].pb(i);
       else root = i;
    }
    nm=1;
    for (i=1;i<=n;i++) if (g[i].size()==0) ans[i]=nm,nm++;
    dfs(root);
    cout << "YES" << endl;
    for (i=1;i<=n;i++) cout << ans[i] << " ";
}


// Problem : B. Numbers on Tree
// Contest : Codeforces - Codeforces Round #612 (Div. 1)
// URL : https://codeforces.com/problemset/problem/1286/B
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define eb emplace_back
#define pb push_back
#define size(s) (int)s.size()
#define int long long
#define vi vector<int>
#define vs vector<string>
#define vv vector<vector<int>>
#define pii pair<int,int>
#define m_p(x,y) make_pair(x,y)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcountll(x)
#define f first
#define se second
#define inc(v,n,x) v.assign(n,x)
#define incd(v,n) v.resize(n)
#define iniz(n) memset(n,0,sizeof(n))
#define inin(n) memset(n,-1,sizeof(n))
#define inimi(n) memset(n,0xc0,sizeof(n))
#define inima(n) memset(n,0x3f,sizeof(n))
#define all(v) (v).begin(),(v).end()

using namespace std;

template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; }
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }

double pi=acos(-1.0);
int md=1e9+7;
const int INF=1e15;
int dx1[]={0,0,-1,1};
int dy1[]={1,-1,0,0};

template<class T>
T abst(T a)
{return a<0?-a:a;}

template<class T>
T max2(T a,T b){return a>b?a:b;}
template<class T>
T min2(T a,T b){return a<b?a:b;}
vi v[2001];
vi val(2001);
vi ans(2001,-1);
void join(vp &v1,vp &v2)
{
	for(auto i:v2)
	v1.pb(i);
}
vp dfs(int x)
{
	//cerr<<x<<" ";
	vp v2;
	for(int ch:v[x])
	{
		vp vt=dfs(ch);
		join(v2,vt);
	}
	if(size(v2))
	sort(all(v2));
	if(size(v2)<val[x])
	{
		cout<<"NO";
		exit(0);
	}
	v2.insert(v2.begin()+val[x],pair<int,int>(val[x]+1,x));
	for(int i=val[x]+1;i<size(v2);i++)
	{
		v2[i].f++;
	}
	return v2;
}
void solve()
{
	int n;cin>>n;
	int root;
	for(int i=0;i<n;i++)
	{
		int x,y;cin>>x>>y;
		if(x==0)
		{
			root=i+1;
		}
		else
		{
			v[x].pb(i+1);
		}
		val[i+1]=y;
	}
	vp ans=dfs(root);
	sort(all(ans),[&](pii p1,pii p2){return p1.se<p2.se;});
		cout<<"YES\n";
		for(int i=1;i<=n;i++)
		cout<<ans[i-1].f<<" ";
}

int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int t=1;
//cin>>t;
for(int i=1;i<=t;i++)
{
    solve();
}
return 0;
}


// Problem : B. Numbers on Tree
// Contest : Codeforces - Codeforces Round #612 (Div. 1)
// URL : https://codeforces.com/problemset/problem/1286/B
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define eb emplace_back
#define pb push_back
#define size(s) (int)s.size()
#define int long long
#define vi vector<int>
#define vs vector<string>
#define vv vector<vector<int>>
#define pii pair<int,int>
#define m_p(x,y) make_pair(x,y)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcountll(x)
#define f first
#define se second
#define inc(v,n,x) v.assign(n,x)
#define incd(v,n) v.resize(n)
#define iniz(n) memset(n,0,sizeof(n))
#define inin(n) memset(n,-1,sizeof(n))
#define inimi(n) memset(n,0xc0,sizeof(n))
#define inima(n) memset(n,0x3f,sizeof(n))
#define all(v) (v).begin(),(v).end()

using namespace std;

template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; }
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }

double pi=acos(-1.0);
int md=1e9+7;
const int INF=1e15;
int dx1[]={0,0,-1,1};
int dy1[]={1,-1,0,0};

template<class T>
T abst(T a)
{return a<0?-a:a;}

template<class T>
T max2(T a,T b){return a>b?a:b;}
template<class T>
T min2(T a,T b){return a<b?a:b;}
vi v[2001];
vi val(2001);
vi ans(2001,-1);
int b=1;
void dfs(int x,vi &v1)
{
	vi vt;
	int cnt=0;
	for(int i=0;i<size(v1);i++)
	{
		if(cnt==val[x])
		{
			cnt++;
			ans[x]=v1[i];
			continue;
		}
		cnt++;
		vt.pb(v1[i]);
	}
	if(ans[x]==-1)
	{
		b=0;return;
	}
	v1=vt;
	for(int ch:v[x])
	{
		dfs(ch,v1);
	}
}
void solve()
{
	int n;cin>>n;
	int root;
	for(int i=0;i<n;i++)
	{
		int x,y;cin>>x>>y;
		if(x==0)
		{
			root=i+1;
		}
		else
		{
			v[x].pb(i+1);
		}
		val[i+1]=y;
	}
	vi v;
	for(int i=1;i<=n;i++)
	v.pb(i);
	dfs(root,v);
	if(b)
	{
		cout<<"YES\n";
		for(int i=1;i<=n;i++)
		cout<<ans[i]<<" ";
	}
	else
	cout<<"NO";
}

int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int t=1;
//cin>>t;
for(int i=1;i<=t;i++)
{
    solve();
}
return 0;
}


// Problem : B. Numbers on Tree
// Contest : Codeforces - Codeforces Round #612 (Div. 1)
// URL : https://codeforces.com/problemset/problem/1286/B
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define eb emplace_back
#define pb push_back
#define size(s) (int)s.size()
#define int long long
#define vi vector<int>
#define vs vector<string>
#define vv vector<vector<int>>
#define pii pair<int,int>
#define m_p(x,y) make_pair(x,y)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcountll(x)
#define f first
#define se second
#define inc(v,n,x) v.assign(n,x)
#define incd(v,n) v.resize(n)
#define iniz(n) memset(n,0,sizeof(n))
#define inin(n) memset(n,-1,sizeof(n))
#define inimi(n) memset(n,0xc0,sizeof(n))
#define inima(n) memset(n,0x3f,sizeof(n))
#define all(v) (v).begin(),(v).end()

using namespace std;

template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; }
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }

double pi=acos(-1.0);
int md=1e9+7;
const int INF=1e15;
int dx1[]={0,0,-1,1};
int dy1[]={1,-1,0,0};

template<class T>
T abst(T a)
{return a<0?-a:a;}

template<class T>
T max2(T a,T b){return a>b?a:b;}
template<class T>
T min2(T a,T b){return a<b?a:b;}
vi v[2001];
vi val(2001);
vi ans(2001,-1);
vp dfs(int x)
{
	vp v2;
	int shift = 0;
	for (int ch:v[x])
	{
		vp r = dfs(ch);
		for (int j = 0; j < size(r); ++j)
			v2.pb(pii(r[j].f+shift, r[j].se));
		shift = v2.back().f;
	}
	if(size(v2)<val[x])
	{
		cout<<"NO";
		exit(0);
	}
	v2.insert(v2.begin()+val[x],pair<int,int>(val[x]+1,x));
	for(int i=val[x]+1;i<size(v2);i++)
	{
		v2[i].f++;
	}
	return v2;
}
void solve()
{
	int n;cin>>n;
	int root;
	for(int i=0;i<n;i++)
	{
		int x,y;cin>>x>>y;
		if(x==0)
		{
			root=i+1;
		}
		else
		{
			v[x].pb(i+1);
		}
		val[i+1]=y;
	}
	vp ans=dfs(root);
	sort(all(ans),[&](pii p1,pii p2){return p1.se<p2.se;});
		cout<<"YES\n";
		for(int i=1;i<=n;i++)
		cout<<ans[i-1].f<<" ";
}

int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int t=1;
//cin>>t;
for(int i=1;i<=t;i++)
{
    solve();
}
return 0;
}