#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
#define maxn 200010

using namespace std;

struct yts
{
	int id,w,w1;
}b[maxn];

priority_queue<pair<int,int> > Q;

int n,m,k;
int d[maxn],d1[maxn],dp[maxn],q[maxn],dp1[maxn];
int head[maxn],to[maxn],nxt[maxn];
int head1[maxn],to1[maxn],nxt1[maxn];
int num,num1;
int a[maxn];
bool flag[maxn];

void addedge(int x,int y)
{
	d[y]++;
	num++;to[num]=y;nxt[num]=head[x];head[x]=num;
}

void addedge1(int x,int y)
{
	d1[y]++;
	num1++;to1[num1]=y;nxt1[num1]=head1[x];head1[x]=num1;
}

bool cmp(yts x,yts y) {return x.w1>y.w1;}

int main()
{
	//freopen("1.in","r",stdin);
	scanf("%d%d%d",&n,&m,&k);
	if (n<k) {puts("-1");return 0;}
	for (int i=1;i<=n;i++) {scanf("%d",&a[i]);flag[a[i]]=1;dp[i]=a[i];}
	for (int i=1;i<=m;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		addedge(y,x);addedge1(x,y);
	}
	int l=0,r=0;
	for (int i=1;i<=n;i++) if (!d[i]) q[++r]=i;
	for (int i=1;i<=n;i++) if (!dp[i]) dp[i]=1;
	while (l<r)
	{
		int x=q[++l];
		for (int p=head[x];p;p=nxt[p])
		{
			dp[to[p]]=max(dp[to[p]],dp[x]+1);
			d[to[p]]--;
			if (!d[to[p]]) q[++r]=to[p];
		}
	}
	if (r!=n) {puts("-1");return 0;}
	for (int i=1;i<=n;i++) if (a[i] && dp[i]!=a[i]) {puts("-1");return 0;}
	l=r=0;
	for (int i=1;i<=n;i++)
	{
		if (!a[i]) dp1[i]=k; else dp1[i]=a[i];
		if (!d1[i]) q[++r]=i;
	}
	while (l<r)
	{
		int x=q[++l];
		for (int p=head1[x];p;p=nxt1[p])
		{
			dp1[to1[p]]=min(dp1[to1[p]],dp1[x]-1);
			d1[to1[p]]--;
			if (!d1[to1[p]]) q[++r]=to1[p];
		}
	}
	r=0;
	for (int i=1;i<=n;i++) if (!a[i]) b[++r]=(yts){i,dp[i],dp1[i]};
	sort(b+1,b+r+1,cmp);
	int now=1;
	for (int i=k;i>=1;i--)
	  if (!flag[i])
	  {
	  	while (now<=r && b[now].w1>=i) Q.push(make_pair(b[now].w,b[now].id)),now++;
	  	int id=0;
	  	while (!Q.empty())
	  	{
	  		id=Q.top().second;
	  		if (dp[id]>i) Q.pop();
	  		else break;
	  	}
	  	if (!id) {puts("-1");return 0;}
	  	a[id]=i;Q.pop();
	  }
	for (int i=1;i<=n;i++)
	{
		if (a[i]) printf("%d",a[i]);
		else printf("%d",dp[i]);
		if (i!=n) printf(" ");
	}
	puts("");
	return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
#define maxn 200010

using namespace std;

struct yts
{
	int id,w,w1;
}b[maxn];

priority_queue<pair<int,int> > Q;

int n,m,k;
int d[maxn],d1[maxn],dp[maxn],q[maxn],dp1[maxn];
int head[maxn],to[maxn],nxt[maxn];
int head1[maxn],to1[maxn],nxt1[maxn];
int num,num1;
int a[maxn];
bool flag[maxn];

void addedge(int x,int y)
{
	d[y]++;
	num++;to[num]=y;nxt[num]=head[x];head[x]=num;
}

void addedge1(int x,int y)
{
	d1[y]++;
	num1++;to1[num1]=y;nxt1[num1]=head1[x];head1[x]=num1;
}

bool cmp(yts x,yts y) {return x.w1>y.w1;}

int main()
{
	//freopen("1.in","r",stdin);
	scanf("%d%d%d",&n,&m,&k);
	if (n<k) {puts("-1");return 0;}
	for (int i=1;i<=n;i++) {scanf("%d",&a[i]);flag[a[i]]=1;dp[i]=a[i];}
	for (int i=1;i<=m;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		addedge(y,x);addedge1(x,y);
	}
	int l=0,r=0;
	for (int i=1;i<=n;i++) if (!d[i]) q[++r]=i;
	for (int i=1;i<=n;i++) if (!dp[i]) dp[i]=1;
	while (l<r)
	{
		int x=q[++l];
		for (int p=head[x];p;p=nxt[p])
		{
			dp[to[p]]=max(dp[to[p]],dp[x]+1);
			d[to[p]]--;
			if (!d[to[p]]) q[++r]=to[p];
		}
	}
	if (r!=n) {puts("-1");return 0;}
	for (int i=1;i<=n;i++) if (a[i] && dp[i]!=a[i]) {puts("-1");return 0;}
	l=r=0;
	for (int i=1;i<=n;i++)
	{
		if (!a[i]) dp1[i]=k; else dp1[i]=a[i];
		if (!d1[i]) q[++r]=i;
	}
	while (l<r)
	{
		int x=q[++l];
		for (int p=head1[x];p;p=nxt1[p])
		{
			dp1[to1[p]]=min(dp1[to1[p]],dp1[x]-1);
			d1[to1[p]]--;
			if (!d1[to1[p]]) q[++r]=to1[p];
		}
	}
	r=0;
	for (int i=1;i<=n;i++) if (!a[i]) b[++r]=(yts){i,dp[i],dp1[i]};
	sort(b+1,b+r+1,cmp);
	int now=1;
	for (int i=k;i>=1;i--)
	  if (!flag[i])
	  {
	  	while (now<=r && b[now].w1>=i) Q.push(make_pair(b[now].w,b[now].id)),now++;
	  	int id=0;
	  	while (!Q.empty())
	  	{
	  		id=Q.top().second;
	  		if (dp[id]>i) Q.pop();
	  		else break;
	  	}
	  	if (!Q.empty()) {puts("-1");return 0;}
	  	a[id]=i;Q.pop();
	  }
	for (int i=1;i<=n;i++)
	{
		if (a[i]) printf("%d",a[i]);
		else printf("%d",dp[i]);
		if (i!=n) printf(" ");
	}
	puts("");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

const int maxn = 2e+5 + 10;
const int INF = 0x7fffffff;

struct edge{
	int v,n;
}e[maxn*2];
struct node{
	int mx,mi,i,c;
	bool operator < (const node &sec) const
	{
		return mx>sec.mx;
	}
}a[maxn];

int n,m,k;
int head[maxn],rd[maxn];

void read()
{
	int i,u,v;

	scanf("%d%d%d",&n,&m,&k);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&a[i].c);a[i].i=i;
		if(a[i].c) a[i].mx=a[i].mi=a[i].c;
		else       a[i].mx=k,a[i].mi=1;
	}
	memset(head,-1,sizeof(head));
	for(i=0;i<m;i++)
	{
		scanf("%d%d",&u,&v);
		e[i<<1].v=v;e[i<<1].n=head[u];head[u]=i<<1;
		e[i<<1|1].v=u;e[i<<1|1].n=head[v];head[v]=i<<1|1;
	}
}

void tuopu(int d)
{
	int i,u,v;
	queue<int> q;

	memset(rd,0,sizeof(rd));
	for(i=0;i<m;i++) rd[e[i<<1|d].v]++;

	for(i=1;i<=n;i++) if(!rd[i]) q.push(i);
	while(!q.empty())
	{
		u=q.front();q.pop();
		for(i=head[u];i!=-1;i=e[i].n) if((i&1)==d)
		{
			v=e[i].v;
			rd[v]--;if(!rd[v]) q.push(v);
			if(d) a[v].mi=max(a[v].mi,a[u].mi+1);
			else  a[v].mx=min(a[v].mx,a[u].mx-1);
		}
	}

	for(i=1;i<=n;i++) if(rd[i]) {printf("-1\n");exit(0);}
}

bool cmpa(node aa,node bb){return aa.mi<bb.mi;}
bool cmpi(node aa,node bb){return aa.i<bb.i;}

void check()
{
	for(int i=1;i<=n;i++) if(a[i].mx<a[i].mi) {printf("-1\n");exit(0);}
}

void solve()
{
	int i,j=1;
	priority_queue<node> q;
	bool del;

	for(i=1;i<=k;i++)
	{
		del=false;
		for(;j<=n && a[j].mi==i;j++)
		{
			node tmp=a[j];tmp.i=j;
			q.push(tmp);
		}
		while(!q.empty() && q.top().mx==i)
		{
			node tmp=q.top();q.pop();
			a[tmp.i].c=i;
			del=true;
		}
		if(!del)
		{
			if(q.empty()) {printf("-1\n");exit(0);}
			node tmp=q.top();q.pop();
			a[tmp.i].c=i;
		}
	}
}

void print()
{
	for(int i=1;i<=n;i++) printf("%d ",a[i].c);
}

int main()
{
//	freopen("2345.in","r",stdin);
//	freopen("2345.out","w",stdout);

	read();
	tuopu(0);
	tuopu(1);
	sort(a+1,a+n+1,cmpa);
	check();
	solve();
	sort(a+1,a+n+1,cmpi);
	print();

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

const int maxn = 2e+5 + 10;
const int INF = 0x7fffffff;

struct edge{
	int v,n;
}e[maxn];
struct node{
	int mx,mi,i,c;
	bool operator < (const node &sec) const
	{
		return mx>sec.mx;
	}
}a[maxn];

int n,m,k;
int head[maxn],rd[maxn];

void read()
{
	int i,u,v;

	scanf("%d%d%d",&n,&m,&k);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&a[i].c);a[i].i=i;
		if(a[i].c) a[i].mx=a[i].mi=a[i].c;
		else       a[i].mx=k,a[i].mi=1;
	}
	memset(head,-1,sizeof(head));
	for(i=0;i<m;i++)
	{
		scanf("%d%d",&u,&v);
		e[i<<1].v=v;e[i<<1].n=head[u];head[u]=i<<1;
		e[i<<1|1].v=u;e[i<<1|1].n=head[v];head[v]=i<<1|1;
	}
}

void tuopu(int d)
{
	int i,u,v;
	queue<int> q;

	memset(rd,0,sizeof(rd));
	for(i=0;i<m;i++) rd[e[i<<1|d].v]++;

	for(i=1;i<=n;i++) if(!rd[i]) q.push(i);
	while(!q.empty())
	{
		u=q.front();q.pop();
		for(i=head[u];i!=-1;i=e[i].n) if((i&1)==d)
		{
			v=e[i].v;
			rd[v]--;if(!rd[v]) q.push(v);
			if(d) a[v].mi=max(a[v].mi,a[u].mi+1);
			else  a[v].mx=min(a[v].mx,a[u].mx-1);
		}
	}

	for(i=1;i<=n;i++) if(rd[i]) {printf("-1\n");exit(0);}
}

bool cmpa(node aa,node bb){return aa.mi<bb.mi;}
bool cmpi(node aa,node bb){return aa.i<bb.i;}

void check()
{
	for(int i=1;i<=n;i++) if(a[i].mx<a[i].mi) {printf("-1\n");exit(0);}
}

void solve()
{
	int i,j=1;
	priority_queue<node> q;
	bool del;

	for(i=1;i<=k;i++)
	{
		del=false;
		for(;j<=n && a[j].mi==i;j++)
		{
			node tmp=a[j];tmp.i=j;
			q.push(tmp);
		}
		while(!q.empty() && q.top().mx==i)
		{
			node tmp=q.top();q.pop();
			a[tmp.i].c=i;
			del=true;
		}
		if(!del)
		{
			if(q.empty()) {printf("-1\n");exit(0);}
			node tmp=q.top();q.pop();
			a[tmp.i].c=i;
		}
	}
}

void print()
{
	for(int i=1;i<=n;i++) printf("%d ",a[i].c);
}

int main()
{
//	freopen("2345.in","r",stdin);
//	freopen("2345.out","w",stdout);

	read();
	tuopu(0);
	tuopu(1);
	sort(a+1,a+n+1,cmpa);
	check();
	solve();
	sort(a+1,a+n+1,cmpi);
	print();

	return 0;
}


#include <iostream>
#include <fstream>
#include <string.h>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <queue>

using namespace std;

const int MAXN = 200006;

struct Tnode
{
	int low,top,i;
	bool operator < (const Tnode &t) const {return top>t.top;}
}a[MAXN];

int head[2][MAXN],cnt[2][MAXN];
int _next[MAXN*2],node[MAXN*2];
int line[MAXN];
int ans[MAXN];
int n,m,k,fp=0;

bool _cmp(Tnode A,Tnode B) {return A.low<B.low;}

void _add(int x,int y,int k)
{
	_next[fp]=head[k][x];
	node[fp]=y;
	head[k][x]=fp++;
}

bool _init(int t)
{
	int he=0,ta=0,u,v;
	for(int i=1;i<=n;i++)
		if(!cnt[t][i]) line[ta++]=i;

	while(he<ta)
	{
		u=line[he++];
		for(int i=head[t][u];i!=-1;i=_next[i])
		{
			v=node[i]; cnt[t][v]--;
			if (t) a[v].top=min(a[v].top,a[u].top-1);
				else a[v].low=max(a[v].low,a[u].low+1);
			if(!cnt[t][v]) line[ta++]=v;
		}
	}
	if (ta<n) return 1;
	return 0;
}

bool solve()
{
	Tnode tmp;
	int j=1;
	priority_queue<Tnode> q;
	bool flag;
	for(int i=1;i<=k;i++)
	{
		flag=0;
		for(;j<=n && a[j].low==i;j++)
		{
			tmp=a[j];tmp.i=j;
			q.push(tmp);
		}
		while(!q.empty() && q.top().top==i)
		{
			tmp=q.top();q.pop();
			ans[a[tmp.i].i]=i;
			flag=true;
		}
		if(!flag)
		{
			if(q.empty()) return 1;
			tmp=q.top();q.pop();
			ans[a[tmp.i].i]=i;
		}
	}
	return 0;
}

bool check()
{
	for(int i=1;i<=n;i++)
		if(a[i].top<a[i].low) return 1;
	return 0;
}

int main()
{
	memset(head,-1,sizeof head);
	int x,y;
	scanf("%d%d%d",&n,&m,&k);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&x);
		a[i].i=i;
		if(x) a[i].top=x,a[i].low=x;
			else a[i].top=k,a[i].low=1;
	}
	for (int i=0;i<m;i++)
	{
		scanf("%d%d",&x,&y);
		_add(y,x,0);
		_add(x,y,1);
		cnt[0][x]++;
		cnt[1][y]++;
	}
	if (_init(0) || _init(1)) return 0&printf("-1\n");
	sort(a+1,a+n+1,_cmp);
	if (check() || solve()) printf("-1\n");
		else
			for (int i=1;i<=n;i++)
				printf("%d ",ans[i]);
	return 0;
}


#include <iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
using namespace std;
const int N=410000;
int r[N],x[N]={0},mxx[N];
int du[N],n;
vector<int>nex[N],pre[N];
queue<int>q;
pair<int, int >p[N],j;
priority_queue<pair<int,int>>q2;
int app[N],len=0,K;
int mx(int i)
{
    int tmp=2*n;
    for(int j=0;j<nex[i].size();j++)tmp=min(x[nex[i][j]]-1,tmp);
    return tmp;
}
bool cmp(pair<int,int>p1,pair<int,int>p2)
{
    if(p1.first!=p2.first)return p1.first<p2.first;
    return mxx[p1.second]>mxx[p2.second];
}
bool bfs()
{
    for(int i=1;i<=n;i++){
        if(du[i]==0)q.push(i);
        x[i]=r[i];
        if(x[i]==0)x[i]=1;
    }
    while(!q.empty())
    {
        int i=q.front();q.pop();
        if(r[i]>0&&x[i]>r[i])return 0;
        for(int j=0;j<nex[i].size();j++)
        {
            int k=nex[i][j];
            du[k]--;
            x[k]=max(x[k],x[i]+1);
            if(du[k]==0)q.push(k);
        }
    }
    for(int i=1;i<=n;i++)
    {
        if(du[i]>0)return 0;
        if(x[i]>K)return 0;
        app[x[i]]++;
        p[i]=make_pair(x[i], i);
        mxx[i]=mx(i);
    }
    return 1;
}
int d[N]={0},del[N];
void dell(int t)
{
    if(del[t])return ;
    del[t]=1;
    for(int k=0;k<pre[t].size();k++)
    {
        int i=pre[t][k];
        d[i]--;
        if(d[i]==0&&r[i]==0)q2.push(make_pair(x[i],i));
    }
}
int rk=0;
int main()
{
    int m,k,u,v;
    cin>>n>>m>>K;
    for(int i=1;i<=n;i++)cin>>r[i];
    for(int i=1;i<=m;i++){
        scanf("%d%d",&u,&v);
        nex[v].push_back(u);
        pre[u].push_back(v);
        du[u]++;
        d[v]++;
    }
    if(!bfs()){cout<<-1<<endl;return 0;}
    for(int i=1;i<=n;i++)if(d[i]==0&&r[i]==0)
    {
        q2.push(make_pair(x[i],i));
    }
    int len=n;
    sort(p+1,p+len+1,cmp);
    for(int i=K;i>=1;i--)if(app[i]==0)
    {
        while(len>0&&p[len].first>i)
        {
            dell(p[len].second);
            len--;
        }
        while(!q2.empty()&&q2.top().first>i){
            q2.pop();
            dell(q2.top().second);
        }
        if(q2.empty()){cout<<-1;return 0;}
        j=q2.top();q2.pop();
        x[j.second]=i;
        app[j.first]--;
        dell(j.second);
    }
    for(int i=1;i<=n;i++)cout<<x[i]<<" ";
}
/*
 2 1 1
 0 0
 2 1

 */


#include <iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
using namespace std;
const int N=410000;
int r[N],x[N]={0},mx[N];
int du[N],n;
vector<int>pre[N],nex[N];
queue<int>q;
pair<int, int >p[N];
int app[N],len=0;
bool bfs()
{
    for(int i=1;i<=n;i++)
    {
        if(du[i]==0)q.push(i);
        mx[i]=2*n;
        x[i]=r[i];
        if(x[i]==0)x[i]=1;
    }
    while(!q.empty())
    {
        int i=q.front();q.pop();
        if(r[i]>0&&x[i]>r[i])
        {
            cout<<"i:"<<i<<endl;
            return 0;
        }
        for(int j=0;j<nex[i].size();j++)
        {
            int k=nex[i][j];
            du[k]--;
            x[k]=max(x[k],x[i]+1);
            if(du[k]==0)q.push(k);
        }
    }
    for(int i=1;i<=n;i++)
    {
        if(du[i]>0)return 0;
        for(int j=0;j<nex[i].size();j++)
        {
            int k=nex[i][j];
            mx[i]=min(mx[i],x[k]-1);
        }
        app[x[i]]++;
        if(r[i]==0)p[++len]=make_pair(x[i], i);
    }
    return 1;
}

int rk=0;
int main()
{
    int m,k,u,v;
    cin>>n>>m>>k;
    for(int i=1;i<=n;i++)cin>>r[i];
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d",&u,&v);
        nex[v].push_back(u);
        pre[u].push_back(v);
        du[u]++;
    }
    if(!bfs())
    {
        cout<<-1<<endl;
       // cout<<"hehe!!"<<endl;
        return 0;
    }
    //for(int i=1;i<=n;i++)cout<<x[i]<<" ";cout<<endl;
    sort(p+1,p+len+1);
    for(int i=k;i>=1;i--)if(app[i]==0)
    {
        while(len>0)
        {
            if(p[len].first>i){len--;continue;}
            int tmp=2*n;
            for(int j=0;j<nex[k].size();j++)tmp=min(x[nex[k][j]]-1,tmp);
            if(tmp<i){len--;continue;}
            else break;
        }
        if(len==0)
        {
            //cout<<"~~~i:"<<i<<endl;
            cout<<-1;
            return 0;
        }
        //cout<<p[len].second<<","<<p[len].first<<"-->"<<i<<endl;
        app[p[len].first]--;
        x[p[len].second]=i;
        len--;
    }
    for(int i=1;i<=n;i++)cout<<x[i]<<" ";
}


#include <iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
using namespace std;
const int N=410000;
int r[N],x[N]={0},mx[N];
int du[N],n;
vector<int>pre[N],nex[N];
queue<int>q;
pair<int, int >p[N];
int app[N],len=0;
bool bfs()
{
    for(int i=1;i<=n;i++)
    {
        if(du[i]==0)q.push(i);
        mx[i]=2*n;
        x[i]=r[i];
        if(x[i]==0)x[i]=1;
    }
    while(!q.empty())
    {
        int i=q.front();q.pop();
        if(r[i]>0&&x[i]>r[i])
        {
           // cout<<"i:"<<i<<endl;
            return 0;
        }
        for(int j=0;j<nex[i].size();j++)
        {
            int k=nex[i][j];
            du[k]--;
            x[k]=max(x[k],x[i]+1);
            if(du[k]==0)q.push(k);
        }
    }
    for(int i=1;i<=n;i++)
    {
        if(du[i]>0)return 0;
        for(int j=0;j<nex[i].size();j++)
        {
            int k=nex[i][j];
            mx[i]=min(mx[i],x[k]-1);
        }
        app[x[i]]++;
        if(r[i]==0)p[++len]=make_pair(x[i], i);
    }
    return 1;
}

int rk=0;
int main()
{
    int m,k,u,v;
    cin>>n>>m>>k;
    for(int i=1;i<=n;i++)cin>>r[i];
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d",&u,&v);
        nex[v].push_back(u);
        pre[u].push_back(v);
        du[u]++;
    }
    if(!bfs())
    {
        cout<<-1<<endl;return 0;
    }
    //for(int i=1;i<=n;i++)cout<<x[i]<<" ";cout<<endl;
    sort(p+1,p+len+1);
    for(int i=k;i>=1;i--)if(app[i]==0)
    {
        while(len>0)
        {
            if(p[len].first>i){len--;continue;}
            int tmp=2*n;
            for(int j=0;j<nex[k].size();j++)tmp=min(x[nex[k][j]]-1,tmp);
            if(tmp<i){len--;continue;}
            else break;
        }
        if(len==0)
        {
            //cout<<"~~~i:"<<i<<endl;
            cout<<-1;
            return 0;
        }
        //cout<<p[len].second<<","<<p[len].first<<"-->"<<i<<endl;
        app[p[len].first]--;
        x[p[len].second]=i;
        len--;
    }
    for(int i=1;i<=n;i++)cout<<x[i]<<" ";
}


#include <iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
using namespace std;
const int N=410000;
int r[N],x[N]={0},mx[N];
int du[N],n;
vector<int>pre[N],nex[N];
queue<int>q;
pair<int, int >p[N];
int app[N],len=0;
bool bfs()
{
    for(int i=1;i<=n;i++)
    {
        if(du[i]==0)q.push(i);
        mx[i]=2*n;
        x[i]=r[i];
        if(x[i]==0)x[i]=1;
    }
    while(!q.empty())
    {
        int i=q.front();q.pop();
        if(r[i]>0&&x[i]>r[i])
        {
            cout<<"i:"<<i<<endl;
            return 0;
        }
        for(int j=0;j<nex[i].size();j++)
        {
            int k=nex[i][j];
            du[k]--;
            x[k]=max(x[k],x[i]+1);
            if(du[k]==0)q.push(k);
        }
    }
    for(int i=1;i<=n;i++)
    {
        if(du[i]>0)return 0;
        for(int j=0;j<nex[i].size();j++)
        {
            int k=nex[i][j];
            mx[i]=min(mx[i],x[k]-1);
        }
        app[x[i]]++;
        if(r[i]!=0)p[++len]=make_pair(x[i], i);
    }
    return 1;
}

int rk=0;
int main()
{
    int m,k,u,v;
    cin>>n>>m>>k;
    for(int i=1;i<=n;i++)cin>>r[i];
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d",&u,&v);
        nex[v].push_back(u);
        pre[u].push_back(v);
        du[u]++;
    }
    if(!bfs())
    {
        cout<<-1<<endl;
       // cout<<"hehe!!"<<endl;
        return 0;
    }
   // for(int i=1;i<=n;i++)cout<<x[i]<<" ";cout<<endl;
    sort(p+1,p+len+1);
    for(int i=k;i>=1;i--)if(app[i]==0)
    {
        while(len>0)
        {
            if(p[len].first>i){len--;continue;}
            int tmp=2*n;
            for(int j=0;j<nex[k].size();j++)tmp=min(x[nex[k][j]]-1,tmp);
            if(tmp<i){len--;continue;}
            else break;
        }
        if(len==0)
        {
            cout<<"~~~i:"<<i<<endl;
            cout<<-1;
            return 0;
        }
        app[p[len].first]--;
        x[p[len].second]=i;
        len--;
    }
    for(int i=1;i<=n;i++)cout<<x[i]<<" ";
}


#include <iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
using namespace std;
const int N=410000;
int r[N],x[N]={0},mxx[N];
int du[N],n;
vector<int>nex[N];
queue<int>q;
pair<int, int >p[N];
int app[N],len=0;
int mx(int i)
{
    int tmp=2*n;
    for(int j=0;j<nex[i].size();j++)tmp=min(x[nex[i][j]]-1,tmp);
    return tmp;
}
bool cmp(pair<int,int>p1,pair<int,int>p2)
{
    if(p1.first!=p2.first)return p1.first<p2.first;
    return mxx[p1.second]>mxx[p2.second];
}
bool bfs()
{
    for(int i=1;i<=n;i++){
        if(du[i]==0)q.push(i);
        x[i]=r[i];
        if(x[i]==0)x[i]=1;
    }
    while(!q.empty())
    {
        int i=q.front();q.pop();
        if(r[i]>0&&x[i]>r[i])return 0;
        for(int j=0;j<nex[i].size();j++)
        {
            int k=nex[i][j];
            du[k]--;
            x[k]=max(x[k],x[i]+1);
            if(du[k]==0)q.push(k);
        }
    }
    for(int i=1;i<=n;i++)
    {
        if(du[i]>0)return 0;
        app[x[i]]++;
        if(r[i]==0)p[++len]=make_pair(x[i], i);
        mxx[i]=mx(i);
    }
    return 1;
}

int rk=0;
int main()
{
    int m,k,u,v;
    cin>>n>>m>>k;
    for(int i=1;i<=n;i++)cin>>r[i];
    for(int i=1;i<=m;i++){
        scanf("%d%d",&u,&v);
        nex[v].push_back(u);
        du[u]++;
    }
    if(!bfs()){cout<<-1<<endl;return 0;}

    sort(p+1,p+len+1,cmp);
    for(int i=k;i>=1;i--)if(app[i]==0)
    {
        while(len>0){
            if(p[len].first>i){len--;continue;}
            if(mx(p[len].second)<i){len--;continue;}
            else break;
        }
        if(len==0){cout<<-1;return 0;}
        app[p[len].first]--;
        x[p[len].second]=i;
        len--;
    }
    for(int i=1;i<=n;i++)cout<<x[i]<<" ";
}


#include <iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
using namespace std;
const int N=410000;
int r[N],x[N]={0},mxx[N];
int du[N],n;
vector<int>nex[N],pre[N];
queue<int>q;
pair<int, int >p[N],j;
priority_queue<pair<int,int>>q2;
int app[N],len=0;
int mx(int i)
{
    int tmp=2*n;
    for(int j=0;j<nex[i].size();j++)tmp=min(x[nex[i][j]]-1,tmp);
    return tmp;
}
bool cmp(pair<int,int>p1,pair<int,int>p2)
{
    if(p1.first!=p2.first)return p1.first<p2.first;
    return mxx[p1.second]>mxx[p2.second];
}
bool bfs()
{
    for(int i=1;i<=n;i++){
        if(du[i]==0)q.push(i);
        x[i]=r[i];
        if(x[i]==0)x[i]=1;
    }
    while(!q.empty())
    {
        int i=q.front();q.pop();
        if(r[i]>0&&x[i]>r[i])return 0;
        for(int j=0;j<nex[i].size();j++)
        {
            int k=nex[i][j];
            du[k]--;
            x[k]=max(x[k],x[i]+1);
            if(du[k]==0)q.push(k);
        }
    }
    for(int i=1;i<=n;i++)
    {
        if(du[i]>0)return 0;
        app[x[i]]++;
        p[i]=make_pair(x[i], i);
        mxx[i]=mx(i);
    }
    return 1;
}
int d[N]={0},del[N];
void dell(int t)
{
    if(del[t])return ;
    del[t]=1;
    for(int k=0;k<pre[t].size();k++)
    {
        int i=pre[t][k];
        d[i]--;
        if(d[i]==0&&r[i]==0)q2.push(make_pair(x[i],i));
    }
}
int rk=0;
int main()
{
    int m,k,u,v;
    cin>>n>>m>>k;
    for(int i=1;i<=n;i++)cin>>r[i];
    for(int i=1;i<=m;i++){
        scanf("%d%d",&u,&v);
        nex[v].push_back(u);
        pre[u].push_back(v);
        du[u]++;
        d[v]++;
    }
    if(!bfs()){cout<<-1<<endl;return 0;}
    for(int i=1;i<=n;i++)if(d[i]==0&&r[i]==0)
    {
        q2.push(make_pair(x[i],i));
    }
    int len=n;
    sort(p+1,p+len+1,cmp);
    for(int i=k;i>=1;i--)if(app[i]==0)
    {
        while(len>0&&p[len].first>i)
        {
            dell(p[len].second);
            len--;
        }
        while(!q2.empty()&&q2.top().first>i){
            q2.pop();
            dell(q2.top().second);
        }
        if(q2.empty()){cout<<-1;return 0;}
        j=q2.top();q2.pop();
        x[j.second]=i;
        app[j.first]--;
        dell(j.second);
    }
    for(int i=1;i<=n;i++)cout<<x[i]<<" ";
}


#include <iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
using namespace std;
const int N=410000;
int r[N],x[N]={0},mxx[N];
int du[N],n;
vector<int>nex[N],pre[N];
queue<int>q;
pair<int, int >p[N],j;
priority_queue<pair<int,int>>q2;
int app[N],len=0;
int mx(int i)
{
    int tmp=2*n;
    for(int j=0;j<nex[i].size();j++)tmp=min(x[nex[i][j]]-1,tmp);
    return tmp;
}
bool cmp(pair<int,int>p1,pair<int,int>p2)
{
    if(p1.first!=p2.first)return p1.first<p2.first;
    return mxx[p1.second]>mxx[p2.second];
}
bool bfs()
{
    for(int i=1;i<=n;i++){
        if(du[i]==0)q.push(i);
        x[i]=r[i];
        if(x[i]==0)x[i]=1;
    }
    while(!q.empty())
    {
        int i=q.front();q.pop();
        if(r[i]>0&&x[i]>r[i])return 0;
        for(int j=0;j<nex[i].size();j++)
        {
            int k=nex[i][j];
            du[k]--;
            x[k]=max(x[k],x[i]+1);
            if(du[k]==0)q.push(k);
        }
    }
    for(int i=1;i<=n;i++)
    {
        if(du[i]>0)return 0;
        if(x[i]>k)return 0;
        app[x[i]]++;
        p[i]=make_pair(x[i], i);
        mxx[i]=mx(i);
    }
    return 1;
}
int d[N]={0},del[N];
void dell(int t)
{
    if(del[t])return ;
    del[t]=1;
    for(int k=0;k<pre[t].size();k++)
    {
        int i=pre[t][k];
        d[i]--;
        if(d[i]==0&&r[i]==0)q2.push(make_pair(x[i],i));
    }
}
int rk=0;
int main()
{
    int m,k,u,v;
    cin>>n>>m>>k;
    for(int i=1;i<=n;i++)cin>>r[i];
    for(int i=1;i<=m;i++){
        scanf("%d%d",&u,&v);
        nex[v].push_back(u);
        pre[u].push_back(v);
        du[u]++;
        d[v]++;
    }
    if(!bfs()){cout<<-1<<endl;return 0;}
    for(int i=1;i<=n;i++)if(d[i]==0&&r[i]==0)
    {
        q2.push(make_pair(x[i],i));
    }
    int len=n;
    sort(p+1,p+len+1,cmp);
    for(int i=k;i>=1;i--)if(app[i]==0)
    {
        while(len>0&&p[len].first>i)
        {
            dell(p[len].second);
            len--;
        }
        while(!q2.empty()&&q2.top().first>i){
            q2.pop();
            dell(q2.top().second);
        }
        if(q2.empty()){cout<<-1;return 0;}
        j=q2.top();q2.pop();
        x[j.second]=i;
        app[j.first]--;
        dell(j.second);
    }
    for(int i=1;i<=n;i++)cout<<x[i]<<" ";
}
/*
 2 1 1
 0 0
 2 1

 */


#include <bits/stdc++.h>
#ifdef DEMETRIO
#define deb(...) fprintf(stderr,__VA_ARGS__)
#define deb1(x) cerr << #x << " = " << x << endl
#else
#define deb(...) 0
#define deb1(x) 0
#endif
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define SZ(x) ((int)x.size())
using namespace std;
typedef long long ll;

void perdi(){puts("-1");exit(0);}

vector<int> g[200005],gi[200005];
int r[200005];
int dp0[200005];
int dp1[200005];
int n,m,k;
priority_queue<pair<int,int> > q;
vector<int> w[200005];

int f0(int x){
	if(dp0[x]>=0)return dp0[x];
	if(dp0[x]==-2)perdi();
	if(r[x]>=0)return dp0[x]=r[x];
	dp0[x]=-2;
	int rr=0;
	for(int y:g[x])rr=max(rr,f0(y)+1);
	if(rr>=k)perdi();
	return dp0[x]=rr;
}

int f1(int x){
	if(dp1[x]>=0)return dp1[x];
	if(r[x]>=0)return dp1[x]=r[x];
	int rr=k-1;
	for(int y:gi[x])rr=min(rr,f1(y)-1);
	if(rr<0)perdi();
	return dp1[x]=rr;
}

int main(){
	scanf("%d%d%d",&n,&m,&k);
	fore(i,0,n)scanf("%d",r+i),r[i]--;
	while(m--){
		int x,y;
		scanf("%d%d",&x,&y);x--;y--;
		g[x].pb(y);gi[y].pb(x);
	}
	memset(dp0,-1,sizeof(dp0));memset(dp1,-1,sizeof(dp1));
	fore(i,0,n)w[f0(i)].pb(i);
	fore(i,0,n)deb("%d %d %d\n",i+1,f0(i)+1,f1(i)+1);
	fore(i,0,k){
		for(int x:w[i])q.push(mp(-f1(x),x));
		while(!q.empty()&&-q.top().fst<i)q.pop();
		if(q.empty())deb("asd %d\n",i+1	),perdi();
		r[q.top().snd]=i;q.pop();
	}
	fore(x,0,n)for(int y:g[x])if(r[x]<=r[y])perdi();
	fore(i,0,n){
		if(r[i]<0)r[i]=f1(i);
		if(i)putchar(' ');
		printf("%d",r[i]+1);
	}
	puts("");
	return 0;
}


#include <bits/stdc++.h>
#ifdef DEMETRIO
#define deb(...) fprintf(stderr,__VA_ARGS__)
#define deb1(x) cerr << #x << " = " << x << endl
#else
#define deb(...) 0
#define deb1(x) 0
#endif
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define SZ(x) ((int)x.size())
using namespace std;
typedef long long ll;

void perdi(){puts("-1");exit(0);}

vector<int> g[200005],gi[200005];
int r[200005];
int dp0[200005];
int dp1[200005];
int n,m,k;
priority_queue<pair<int,int> > q;
vector<int> w[200005];

int f0(int x){
	if(dp0[x]>=0)return dp0[x];
	if(dp0[x]==-2)perdi();
	if(r[x]>=0)return dp0[x]=r[x];
	dp0[x]=-2;
	int rr=0;
	for(int y:g[x])rr=max(rr,f0(y)+1);
	if(rr>=k)perdi();
	return dp0[x]=rr;
}

int f1(int x){
	if(dp1[x]>=0)return dp1[x];
	if(r[x]>=0)return dp1[x]=r[x];
	int rr=k-1;
	for(int y:gi[x])rr=min(rr,f1(y)-1);
	if(rr<0)perdi();
	return dp1[x]=rr;
}

int main(){
	scanf("%d%d%d",&n,&m,&k);
	fore(i,0,n)scanf("%d",r+i),r[i]--;
	while(m--){
		int x,y;
		scanf("%d%d",&x,&y);x--;y--;
		g[x].pb(y);gi[y].pb(x);
	}
	memset(dp0,-1,sizeof(dp0));memset(dp1,-1,sizeof(dp1));
	fore(i,0,n)w[f0(i)].pb(i);
	fore(i,0,n)deb("%d %d %d\n",i+1,f0(i)+1,f1(i)+1);
	fore(i,0,k){
		for(int x:w[i])q.push(mp(-f1(x),x));
		while(!q.empty()&&-q.top().fst<i)q.pop();
		if(q.empty())deb("asd %d\n",i+1	),perdi();
		r[q.top().snd]=i;q.pop();
	}
	fore(i,0,n)if(r[i]<0)r[i]=f1(i);
	fore(x,0,n)for(int y:g[x])if(r[x]<=r[y])perdi();
	fore(i,0,n){
		if(i)putchar(' ');
		printf("%d",r[i]+1);
	}
	puts("");
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>

const int maxn = 200000 + 5;
const int maxm = 200000 + 5;

// normal reverse
std::vector<int> nG[maxn];
std::vector<int> rG[maxn];

void add_edge(int u, int v, bool rev = 0) {
	auto &G = (rev ? rG : nG);
	G[u].push_back(v);
}

void init_edge() {
	for (int i = 0; i < maxn; i++) {
		nG[i].clear();
		rG[i].clear();
	}
}

int n, m, k;
int in[maxn];
int min_rank[maxn], max_rank[maxn], r[maxn];

struct Node {
	int min_rank;
	int id;
	const bool operator < (const Node &rhs) const {
		return min_rank < rhs.min_rank;
	}
};

std::vector<Node> s[maxn];
std::vector<int> topo;
void toposort() {
	std::queue<int> Q;
	for (int i = 1; i <= n; i++) {
		if (!in[i]) {
			Q.push(i);
			topo.push_back(i);
		}
	}

	while (!Q.empty()) {
		int u = Q.front(); Q.pop();
		for (int i = 0; i < nG[u].size(); i++) {
			int v = nG[u][i];
			in[v]--;
			if (!in[v]) {
				Q.push(v);
				topo.push_back(v);
			}
		}
	}
}
int main() {
	scanf("%d%d%d", &n, &m, &k);
	for (int i = 1; i <= n; i++) {
		scanf("%d", r + i);
		max_rank[i] = r[i] ? r[i] : k;
		min_rank[i] = r[i] ? r[i] : 1;
	}
	init_edge();
	int u, v;
	for (int i = 0; i < m; i++) {
		scanf("%d%d", &u, &v);
		add_edge(u, v);
		in[v]++;
		add_edge(v, u, 1);
	}

	toposort();

	printf("%d\n", topo.size());
	if (topo.size() != n) {
		puts("-1");
		return 0;
	}

	/*for (int i = 0; i < topo.size(); i++) {
		printf("%d ", topo[i]);
	}
	puts("");*/

	for (int i = 0; i < topo.size(); i++) {
		u = topo[i];
		for (int j = 0; j < nG[u].size(); j++) {
			v = nG[u][j];
			max_rank[v] = std::min(max_rank[v], max_rank[u] - 1);
		}
	}

	for (int i = topo.size() - 1; i >= 0; i--) {
		u = topo[i];
		for (int j = 0; j < rG[u].size(); j++) {
			v = rG[u][j];
			min_rank[v] = std::max(min_rank[v], min_rank[u] + 1);
		}
	}
	/*for (int i = 1; i <= n; i++) {
		printf("min:%d %d %d\n", i, min_rank[i], max_rank[i]);
	}*/

	for (int i = 1; i <= n; i++) {
		if (max_rank[i] < min_rank[i]) {
			puts("-1");
			return 0;
		} else {
			s[max_rank[i]].push_back((Node) {min_rank[i], i});
		}
	}

	std::priority_queue<Node> Q;
	for (int i = k; i > 0; i--) {
		for (int j = 0; j < s[i].size(); j++) {
			Q.push(s[i][j]);
		}

		if (Q.empty()) {
			puts("-1");
			return 0;
		}
		int x = Q.top().id; Q.pop();
		r[x] = i;
		while (!Q.empty() && Q.top().min_rank == i) {
			r[Q.top().id] = i;
			Q.pop();
		}
	}

	for (int i = 1; i <= n; i++) {
		printf("%d ", r[i]);
	}
	printf("\n");
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>

const int maxn = 200000 + 5;
const int maxm = 200000 + 5;

// normal reverse
std::vector<int> nG[maxn];
std::vector<int> rG[maxn];

void add_edge(int u, int v, bool rev = 0) {
	auto &G = (rev ? rG : nG);
	G[u].push_back(v);
}

void init_edge() {
	for (int i = 0; i < maxn; i++) {
		nG[i].clear();
		rG[i].clear();
	}
}

int n, m, k;
int in[maxn];
int min_rank[maxn], max_rank[maxn], r[maxn];

struct Node {
	int min_rank;
	int id;
	const bool operator < (const Node &rhs) const {
		return min_rank < rhs.min_rank;
	}
};

std::vector<Node> s[maxn];
std::vector<int> topo;
void toposort() {
	std::queue<int> Q;
	for (int i = 1; i <= n; i++) {
		if (!in[i]) {
			Q.push(i);
			topo.push_back(i);
		}
	}

	while (!Q.empty()) {
		int u = Q.front(); Q.pop();
		for (int i = 0; i < nG[u].size(); i++) {
			int v = nG[u][i];
			in[v]--;
			if (!in[v]) {
				Q.push(v);
				topo.push_back(v);
			}
		}
	}
}
int main() {
	scanf("%d%d%d", &n, &m, &k);
	for (int i = 1; i <= n; i++) {
		scanf("%d", r + i);
		max_rank[i] = r[i] ? r[i] : k;
		min_rank[i] = r[i] ? r[i] : 1;
	}
	init_edge();
	int u, v;
	for (int i = 0; i < m; i++) {
		scanf("%d%d", &u, &v);
		add_edge(u, v);
		in[u]++;
		add_edge(v, u, 1);
	}

	toposort();
	// printf("%d\n", topo.size());

	/*for (int i = 0; i < topo.size(); i++) {
		printf("%d ", topo[i]);
	}
	puts("");*/

	for (int i = 0; i < topo.size(); i++) {
		u = topo[i];
		for (int j = 0; j < nG[u].size(); j++) {
			v = nG[u][j];
			max_rank[v] = std::min(max_rank[v], max_rank[u] - 1);
		}
	}

	for (int i = topo.size() - 1; i >= 0; i--) {
		u = topo[i];
		for (int j = 0; j < rG[u].size(); j++) {
			v = rG[u][j];
			min_rank[v] = std::max(min_rank[v], min_rank[u] + 1);
		}
	}
	/*for (int i = 1; i <= n; i++) {
		printf("min:%d %d %d\n", i, min_rank[i], max_rank[i]);
	}*/

	for (int i = 1; i <= n; i++) {
		if (max_rank[i] < min_rank[i]) {
			puts("-1");
			return 0;
		} else {
			s[max_rank[i]].push_back((Node) {min_rank[i], i});
		}
	}

	std::priority_queue<Node> Q;
	for (int i = k; i > 0; i--) {
		for (int j = 0; j < s[i].size(); j++) {
			Q.push(s[i][j]);
		}

		if (Q.empty()) {
			puts("-1");
			return 0;
		}
		int x = Q.top().id; Q.pop();
		r[x] = i;
		while (!Q.empty() && Q.top().min_rank == i) {
			r[Q.top().id] = i;
			Q.pop();
		}

	}

	for (int i = 1; i <= n; i++) {
		printf("%d ", r[i]);
	}
	printf("\n");
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>

const int maxn = 200000 + 5;
const int maxm = 200000 + 5;

// normal reverse
std::vector<int> nG[maxn];
std::vector<int> rG[maxn];

void add_edge(int u, int v, bool rev = 0) {
	auto &G = (rev ? rG : nG);
	G[u].push_back(v);
}

void init_edge() {
	for (int i = 0; i < maxn; i++) {
		nG[i].clear();
		rG[i].clear();
	}
}

int n, m, k;
int in[maxn];
int min_rank[maxn], max_rank[maxn], r[maxn];

struct Node {
	int min_rank;
	int id;
	const bool operator < (const Node &rhs) const {
		return min_rank < rhs.min_rank;
	}
};

std::vector<Node> s[maxn];
std::vector<int> topo;
void toposort() {
	std::queue<int> Q;
	for (int i = 1; i <= n; i++) {
		if (!in[i]) {
			Q.push(i);
			topo.push_back(i);
		}
	}

	while (!Q.empty()) {
		int u = Q.front(); Q.pop();
		for (int i = 0; i < rG[u].size(); i++) {
			int v = rG[u][i];
			in[v]--;
			if (!in[v]) {
				Q.push(v);
				topo.push_back(v);
			}
		}
	}
}
int main() {
	scanf("%d%d%d", &n, &m, &k);
	for (int i = 1; i <= n; i++) {
		scanf("%d", r + i);
		max_rank[i] = r[i] ? r[i] : k;
		min_rank[i] = r[i] ? r[i] : 1;
	}
	init_edge();
	int u, v;
	for (int i = 0; i < m; i++) {
		scanf("%d%d", &u, &v);
		add_edge(u, v);
		in[u]++;
		add_edge(v, u, 1);
	}

	toposort();

	// printf("%d\n", topo.size());
	if (topo.size() != n) {
		puts("-1");
		return 0;
	}

	/*for (int i = 0; i < topo.size(); i++) {
		printf("%d ", topo[i]);
	}
	puts("");*/

	for (int i = 0; i < topo.size(); i++) {
		u = topo[i];
		for (int j = 0; j < nG[u].size(); j++) {
			v = nG[u][j];
			max_rank[v] = std::min(max_rank[v], max_rank[u] - 1);
		}
	}

	for (int i = topo.size() - 1; i >= 0; i--) {
		u = topo[i];
		for (int j = 0; j < rG[u].size(); j++) {
			v = rG[u][j];
			min_rank[v] = std::max(min_rank[v], min_rank[u] + 1);
		}
	}
	/*for (int i = 1; i <= n; i++) {
		printf("min:%d %d %d\n", i, min_rank[i], max_rank[i]);
	}*/

	for (int i = 1; i <= n; i++) {
		if (max_rank[i] < min_rank[i]) {
			puts("-1");
			return 0;
		} else {
			s[max_rank[i]].push_back((Node) {min_rank[i], i});
		}
	}

	std::priority_queue<Node> Q;
	for (int i = k; i > 0; i--) {
		for (int j = 0; j < s[i].size(); j++) {
			Q.push(s[i][j]);
		}

		if (Q.empty()) {
			puts("-1");
			return 0;
		}
		int x = Q.top().id; Q.pop();
		r[x] = i;
		while (!Q.empty() && Q.top().min_rank == i) {
			r[Q.top().id] = i;
			Q.pop();
		}

	}

	for (int i = 1; i <= n; i++) {
		printf("%d ", r[i]);
	}
	printf("\n");
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>

const int maxn = 200000 + 5;
const int maxm = 200000 + 5;

// normal reverse
std::vector<int> nG[maxn];
std::vector<int> rG[maxn];

void add_edge(int u, int v, bool rev = 0) {
	auto &G = (rev ? rG : nG);
	G[u].push_back(v);
}

void init_edge() {
	for (int i = 0; i < maxn; i++) {
		nG[i].clear();
		rG[i].clear();
	}
}

int n, m, k;
int in[maxn];
int min_rank[maxn], max_rank[maxn], r[maxn];

struct Node {
	int min_rank;
	int id;
	const bool operator < (const Node &rhs) const {
		return min_rank < rhs.min_rank;
	}
};

std::vector<Node> s[maxn];
std::vector<int> topo;
void toposort() {
	std::queue<int> Q;
	for (int i = 1; i <= n; i++) {
		if (!in[i]) {
			Q.push(i);
			topo.push_back(i);
		}
	}

	while (!Q.empty()) {
		int u = Q.front(); Q.pop();
		for (int i = 0; i < nG[u].size(); i++) {
			int v = nG[u][i];
			in[v]--;
			if (!in[v]) {
				Q.push(v);
				topo.push_back(v);
			}
		}
	}
}
int main() {
	scanf("%d%d%d", &n, &m, &k);
	for (int i = 1; i <= n; i++) {
		scanf("%d", r + i);
		max_rank[i] = r[i] ? r[i] : k;
		min_rank[i] = r[i] ? r[i] : 1;
	}
	init_edge();
	int u, v;
	for (int i = 0; i < m; i++) {
		scanf("%d%d", &u, &v);
		add_edge(u, v);
		in[v]++;
		add_edge(v, u, 1);
	}

	toposort();

	// printf("%d\n", topo.size());
	if (topo.size() != n) {
		puts("-1");
		return 0;
	}

	/*for (int i = 0; i < topo.size(); i++) {
		printf("%d ", topo[i]);
	}
	puts("");*/

	for (int i = 0; i < topo.size(); i++) {
		u = topo[i];
		for (int j = 0; j < nG[u].size(); j++) {
			v = nG[u][j];
			max_rank[v] = std::min(max_rank[v], max_rank[u] - 1);
		}
	}

	for (int i = topo.size() - 1; i >= 0; i--) {
		u = topo[i];
		for (int j = 0; j < rG[u].size(); j++) {
			v = rG[u][j];
			min_rank[v] = std::max(min_rank[v], min_rank[u] + 1);
		}
	}
	/*for (int i = 1; i <= n; i++) {
		printf("min:%d %d %d\n", i, min_rank[i], max_rank[i]);
	}*/

	for (int i = 1; i <= n; i++) {
		if (max_rank[i] < min_rank[i]) {
			puts("-1");
			return 0;
		} else {
			s[max_rank[i]].push_back((Node) {min_rank[i], i});
		}
	}

	std::priority_queue<Node> Q;
	for (int i = k; i > 0; i--) {
		for (int j = 0; j < s[i].size(); j++) {
			Q.push(s[i][j]);
		}

		if (Q.empty()) {
			puts("-1");
			return 0;
		}
		int x = Q.top().id; Q.pop();
		r[x] = i;
		while (!Q.empty() && Q.top().min_rank == i) {
			r[Q.top().id] = i;
			Q.pop();
		}
	}

	for (int i = 1; i <= n; i++) {
		printf("%d ", r[i]);
	}
	printf("\n");
}


#include <bits/stdc++.h>
using std::pair;
using std::make_pair;
#define fi first
#define se second
#define mp make_pair
using std::queue;
using std::vector;
using std::min;
using std::max;
typedef pair<int,int> pii;
const int N=200005;
int to[N],Next[N],last[N],l[N],r[N],edge,a[N],n,m,k,d[N],ans[N];
struct note{
	int x,y;
}e[N];
queue<int> q;
vector<int> v[N];
std::priority_queue<pii> Q;
void add(int x,int y){
	to[++edge]=y;
	Next[edge]=last[x];
	last[x]=edge;
}
void ter(){
	puts("-1");
	exit(0);
}
void solvemax(){
	memcpy(r,a,sizeof(a));
	for (int i=1;i<=n;i++)
		if (!r[i]) r[i]=k;
	for (int i=1;i<=m;i++){
		add(e[i].x,e[i].y);
		d[e[i].y]++;
	}
	for (int i=1;i<=n;i++)
		if (!d[i]) q.push(i);
	int cnt=0;
	while (!q.empty()){
		cnt++;
		int x=q.front();
		q.pop();
		for (int i=last[x];i;i=Next[i]){
			int u=to[i];
			r[u]=min(r[u],r[x]-1);
			d[u]--;
			if (!d[u]) q.push(u);
		}
	}
	if (cnt!=n) ter();
}
void solvemin(){
	memcpy(l,a,sizeof(a));
	memset(last,0,sizeof(last));
	edge=0;
	for (int i=1;i<=n;i++) if (!l[i]) l[i]=1;
	for (int i=1;i<=m;i++){
		add(e[i].y,e[i].x);
		d[e[i].x]++;
	}
	for (int i=1;i<=n;i++)
		if (!d[i]) q.push(i);
	while (!q.empty()){
		int x=q.front();
		q.pop();
		for (int i=last[x];i;i=Next[i]){
			int u=to[i];
			l[u]=max(l[u],l[x]+1);
			d[u]--;
			if (!d[u]) q.push(u);
		}
	}
}
int main(){
	scanf("%d%d%d",&n,&m,&k);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	for (int i=1;i<=m;i++)
		scanf("%d%d",&e[i].x,&e[i].y);
	solvemax();
	solvemin();
	for (int i=1;i<=n;i++)
		if ((r[i]<l[i]) || (a[i] && (a[i]!=l[i] || a[i]!=r[i])))
			ter();
	for (int i=1;i<=n;i++) v[r[i]].push_back(i);
	for (int i=k;i>=1;i--){
		for (auto j:v[i]) Q.push(mp(l[j],j));
		if (Q.empty()) ter();
		int x=Q.top().se;
		Q.pop();
		ans[x]=i;
		while(Q.size()){
			int x=Q.top().se;
			if (l[x]<i) break;
			ans[x]=i;
			Q.pop();
		}
	}
	for (int i=1;i<=n;i++) printf("%d ",ans[i]);
}


#include <bits/stdc++.h>

using namespace std;

#define MAXN 300000

int n, m, k, d[MAXN], dr[MAXN], r[MAXN], rr[MAXN], lr[MAXN];
vector<int> e[MAXN], er[MAXN];

int main() {
    cin >> n >> m >> k;
    for (int i = 0; i < n; i++) {
        cin >> r[i];
        if (r[i] == 0)
            lr[i] = 1, rr[i] = k;
        else
            lr[i] = rr[i] = r[i];
    }
    int x, y;
    for (int i = 0; i < m; i++)
        cin >> x >> y, x--, y--, e[x].push_back(y), d[y]++, er[y].push_back(x), dr[x]++;

    queue<int> q;
    for (int i = 0; i < n; i++)
        if (d[i] == 0)
            q.push(i);
    int c = 0;
    while (!q.empty()) {
        int i = q.front();
        c++, q.pop();
        for (int j : e[i]) {
            rr[j] = min(rr[j], rr[i] - 1), d[j]--;
            if (d[j] == 0)
                q.push(j);
        }
    }
    for (int i = 0; i < n; i++)
        if (dr[i] == 0)
            q.push(i);
    while (!q.empty()) {
        int i = q.front();
        q.pop();
        for (int j : er[i]) {
            lr[j] = max(lr[j], lr[i] + 1), dr[j]--;
            if (dr[j] == 0)
                q.push(j);
        }
    }
    bool pos = c == n;
    for (int i = 0; i < n; i++)
        pos = pos && lr[i] <= rr[i];

    if (pos) {
        priority_queue<pair<pair<int, int>, int>> pq;
        for (int i = 0; i < n; i++)
            pq.push({{rr[i], lr[i]}, i});
        c = k;
        while (!pq.empty()) {
            pair<pair<int, int>, int> p = pq.top();
            pq.pop();
            int i = p.second;
            if (rr[i] < c) {
                pos = false;
                break;
            }
            r[i] = max(lr[i], c);
            if (r[i] == c)
                c--;
        }
    }
    pos = pos && c == 0;

    if (!pos)
        cout << -1 << "\n";
    else
        for (int i = 0; i < n; i++)
            cout << r[i] << "\n";
}


#include <bits/stdc++.h>

using namespace std;

#define MAXN 300000

int n, m, k, d[MAXN], dr[MAXN], r[MAXN], rr[MAXN], lr[MAXN];
vector<int> e[MAXN], er[MAXN];
vector<int> ver[MAXN];

int main() {
    cin >> n >> m >> k;
    for (int i = 0; i < n; i++) {
        cin >> r[i];
        if (r[i] == 0)
            lr[i] = 1, rr[i] = k;
        else
            lr[i] = rr[i] = r[i];
    }
    int x, y;
    for (int i = 0; i < m; i++)
        cin >> x >> y, x--, y--, e[x].push_back(y), d[y]++, er[y].push_back(x), dr[x]++;

    queue<int> q;
    for (int i = 0; i < n; i++)
        if (d[i] == 0)
            q.push(i);
    int c = 0;
    while (!q.empty()) {
        int i = q.front();
        c++, q.pop();
        for (int j : e[i]) {
            rr[j] = min(rr[j], rr[i] - 1), d[j]--;
            if (d[j] == 0)
                q.push(j);
        }
    }
    for (int i = 0; i < n; i++)
        if (dr[i] == 0)
            q.push(i);
    while (!q.empty()) {
        int i = q.front();
        q.pop();
        for (int j : er[i]) {
            lr[j] = max(lr[j], lr[i] + 1), dr[j]--;
            if (dr[j] == 0)
                q.push(j);
        }
    }
    bool pos = c == n && k <= n;
    for (int i = 0; i < n; i++)
        pos = pos && lr[i] <= rr[i];
    if (pos)
        for (int i = 0; i < n; i++)
            ver[rr[i]].push_back(i);

    if (pos) {
        priority_queue<pair<int, int>> pq;
        c = k;
        for (int i : ver[c])
            pq.push({lr[i], i});
        while (!pq.empty()) {
            pair<int, int> p = pq.top();
            pq.pop();
            int i = p.second;
            if (rr[i] < c) {
                pos = false;
                break;
            }
            r[i] = max(lr[i], c);
            if (r[i] == c) {
                c--;
                if (c > 0)
                    for (int i : ver[c])
                        pq.push({lr[i], i});
            }
        }
    }
    pos = pos && c == 0;

    if (!pos)
        cout << -1 << "\n";
    else
        for (int i = 0; i < n; i++)
            cout << r[i] << "\n";
}


#include <bits/stdc++.h>

using namespace std;

#define MAXN 300000

int n, m, k, d[MAXN], dr[MAXN], r[MAXN], rr[MAXN], lr[MAXN];
vector<int> e[MAXN], er[MAXN];

int main() {
    cin >> n >> m >> k;
    for (int i = 0; i < n; i++) {
        cin >> r[i];
        if (r[i] == 0)
            lr[i] = 1, rr[i] = k;
        else
            lr[i] = rr[i] = r[i];
    }
    int x, y;
    for (int i = 0; i < m; i++)
        cin >> x >> y, x--, y--, e[x].push_back(y), d[y]++, er[y].push_back(x), dr[x]++;

    queue<int> q;
    for (int i = 0; i < n; i++)
        if (d[i] == 0)
            q.push(i);
    int c = 0;
    while (!q.empty()) {
        int i = q.front();
        c++, q.pop();
        for (int j : e[i]) {
            rr[j] = min(rr[j], rr[i] - 1), d[j]--;
            if (d[j] == 0)
                q.push(j);
        }
    }
    for (int i = 0; i < n; i++)
        if (dr[i] == 0)
            q.push(i);
    while (!q.empty()) {
        int i = q.front();
        q.pop();
        for (int j : er[i]) {
            lr[j] = max(lr[j], lr[i] + 1), dr[j]--;
            if (dr[j] == 0)
                q.push(j);
        }
    }
    bool pos = c == n && k <= n;
    for (int i = 0; i < n; i++)
        pos = pos && lr[i] <= rr[i];

    if (pos) {
        priority_queue<pair<pair<int, int>, int>> pq;
        for (int i = 0; i < n; i++)
            pq.push({{rr[i], lr[i]}, i});
        c = k;
        while (!pq.empty()) {
            pair<pair<int, int>, int> p = pq.top();
            pq.pop();
            int i = p.second;
            /*if (rr[i] < c) {
                pos = false;
                break;
            }*/
            r[i] = max(lr[i], c);
            if (r[i] == c)
                c--;
        }
    }
    pos = pos && c == 0;

    if (!pos)
        cout << -1 << "\n";
    else
        for (int i = 0; i < n; i++)
            cout << r[i] << "\n";
}


#include <bits/stdc++.h>

using namespace std;

#define MAXN 300000

int n, m, k, d[MAXN], dr[MAXN], r[MAXN], rr[MAXN], lr[MAXN];
vector<int> e[MAXN], er[MAXN];

int main() {
    cin >> n >> m >> k;
    for (int i = 0; i < n; i++) {
        cin >> r[i];
        if (r[i] == 0)
            lr[i] = 1, rr[i] = k;
        else
            lr[i] = rr[i] = r[i];
    }
    int x, y;
    for (int i = 0; i < m; i++)
        cin >> x >> y, x--, y--, e[x].push_back(y), d[y]++, er[y].push_back(x), dr[x]++;

    queue<int> q;
    for (int i = 0; i < n; i++)
        if (d[i] == 0)
            q.push(i);
    int c = 0;
    while (!q.empty()) {
        int i = q.front();
        c++, q.pop();
        for (int j : e[i]) {
            rr[j] = min(rr[j], rr[i] - 1), d[j]--;
            if (d[j] == 0)
                q.push(j);
        }
    }
    for (int i = 0; i < n; i++)
        if (dr[i] == 0)
            q.push(i);
    while (!q.empty()) {
        int i = q.front();
        q.pop();
        for (int j : er[i]) {
            lr[j] = max(lr[j], lr[i] + 1), dr[j]--;
            if (dr[j] == 0)
                q.push(j);
        }
    }
    bool pos = c == n && k <= n;
    for (int i = 0; i < n; i++)
        pos = pos && lr[i] <= rr[i];

    if (pos) {
        priority_queue<pair<pair<int, int>, int>> pq;
        for (int i = 0; i < n; i++)
            pq.push({{rr[i], lr[i]}, i});
        c = k;
        while (!pq.empty()) {
            pair<pair<int, int>, int> p = pq.top();
            pq.pop();
            int i = p.second;
            if (rr[i] < c) {
                pos = false;
                break;
            }
            r[i] = max(lr[i], c);
            if (r[i] == c)
                c--;
        }
    }
    pos = pos && c == 0;

    if (!pos)
        cout << -1 << "\n";
    else
        for (int i = 0; i < n; i++)
            cout << r[i] << "\n";
}


#include <bits/stdc++.h>

using namespace std;

#define MAXN 300000

int n, m, k, d[MAXN], dr[MAXN], r[MAXN], rr[MAXN], lr[MAXN];
vector<int> e[MAXN], er[MAXN];
vector<int> ver[MAXN];

int main() {
    cin >> n >> m >> k;
    for (int i = 0; i < n; i++) {
        cin >> r[i];
        if (r[i] == 0)
            lr[i] = 1, rr[i] = k;
        else
            lr[i] = rr[i] = r[i];
    }
    int x, y;
    for (int i = 0; i < m; i++)
        cin >> x >> y, x--, y--, e[x].push_back(y), d[y]++, er[y].push_back(x), dr[x]++;

    queue<int> q;
    for (int i = 0; i < n; i++)
        if (d[i] == 0)
            q.push(i);
    int c = 0;
    while (!q.empty()) {
        int i = q.front();
        c++, q.pop();
        for (int j : e[i]) {
            rr[j] = min(rr[j], rr[i] - 1), d[j]--;
            if (d[j] == 0)
                q.push(j);
        }
    }
    for (int i = 0; i < n; i++)
        if (dr[i] == 0)
            q.push(i);
    while (!q.empty()) {
        int i = q.front();
        q.pop();
        for (int j : er[i]) {
            lr[j] = max(lr[j], lr[i] + 1), dr[j]--;
            if (dr[j] == 0)
                q.push(j);
        }
    }
    bool pos = c == n && k <= n;
    for (int i = 0; i < n; i++)
        pos = pos && lr[i] <= rr[i];
    for (int i = 0; i < n; i++)
        ver[rr[i]].push_back(i);

    if (pos) {
        priority_queue<pair<int, int>> pq;
        c = k;
        for (int i : ver[c])
            pq.push({lr[i], i});
        while (!pq.empty()) {
            pair<int, int> p = pq.top();
            pq.pop();
            int i = p.second;
            if (rr[i] < c) {
                pos = false;
                break;
            }
            r[i] = max(lr[i], c);
            if (r[i] == c) {
                c--;
                if (c > 0)
                    for (int i : ver[c])
                        pq.push({lr[i], i});
            }
        }
    }
    pos = pos && c == 0;

    if (!pos)
        cout << -1 << "\n";
    else
        for (int i = 0; i < n; i++)
            cout << r[i] << "\n";
}


#include <bits/stdc++.h>

using namespace std;

int n, m, k, d[200000], dr[200000], r[200000], rr[200000], lr[200000];
vector<int> e[200000], er[200000];

int main() {
    cin >> n >> m >> k;
    for (int i = 0; i < n; i++) {
        cin >> r[i];
        if (r[i] == 0)
            lr[i] = 1, rr[i] = k;
        else
            lr[i] = rr[i] = r[i];
    }
    int x, y;
    for (int i = 0; i < m; i++)
        cin >> x >> y, x--, y--, e[x].push_back(y), d[y]++, er[y].push_back(x), dr[x]++;

    queue<int> q;
    for (int i = 0; i < n; i++)
        if (d[i] == 0)
            q.push(i);
    int c = 0;
    while (!q.empty()) {
        int i = q.front();
        c++, q.pop();
        for (int j : e[i]) {
            rr[j] = min(rr[j], rr[i] - 1), d[j]--;
            if (d[j] == 0)
                q.push(j);
        }
    }
    for (int i = 0; i < n; i++)
        if (dr[i] == 0)
            q.push(i);
    while (!q.empty()) {
        int i = q.front();
        q.pop();
        for (int j : er[i]) {
            lr[j] = max(lr[j], lr[i] + 1), dr[j]--;
            if (dr[j] == 0)
                q.push(j);
        }
    }
    bool pos = c == n;
    for (int i = 0; i < n; i++)
        pos = pos && lr[i] <= rr[i];

    if (pos) {
        priority_queue<pair<pair<int, int>, int>> pq;
        for (int i = 0; i < n; i++)
            pq.push({{rr[i], lr[i]}, i});
        c = k;
        while (!pq.empty()) {
            pair<pair<int, int>, int> p = pq.top();
            pq.pop();
            int i = p.second;
            if (rr[i] < c) {
                pos = false;
                break;
            }
            r[i] = max(lr[i], c);
            if (r[i] == c)
                c--;
        }
    }
    pos = pos && c == 0;

    if (!pos)
        cout << -1 << "\n";
    else
        for (int i = 0; i < n; i++)
            cout << r[i] << "\n";
}


#include<bits/stdc++.h>
#define PII pair<int,int>
#define f first
#define s second
#define VI vector<int>
#define LL long long
#define MP make_pair
#define LD long double
#define PB push_back
#define ALL(V) V.begin(),V.end()
#define abs(x) max((x),-(x))
#define PDD pair<LD,LD>
#define VPII vector< PII >
#define siz(V) ((int)V.size())
#define FOR(x, b, e)  for(int x=b;x<=(e);x++)
#define FORD(x, b, e) for(int x=b;x>=(e);x--)
#define REP(x, n)     for(int x=0;x<(n);x++)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#ifdef DEB
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif
using namespace std;
int n, m, k;
const int MXN = 2e5+5;
int r[MXN];
int perm[MXN];
#define per perm
VI V[MXN], Vi[MXN];
int sto[MXN];
int low[MXN], high[MXN];
void err() {
    printf("-1\n");
    exit(0);
}
int main()
    {
    scanf("%d%d%d", &n, &m, &k);
    FOR(i, 1, n)
        scanf("%d", &r[i]);

    REP(i, m)
        {
        int a, b;
        scanf("%d%d", &a, &b);
        V[b].PB(a);
        Vi[a].PB(b);
        sto[a]++;
        }
    queue<int> q;
    FOR(i, 1, n)
        if(sto[i] == 0)
            q.push(i);
    int il = 0;
    while(q.size())
        {
        int x;
        perm[++il] = x = q.front();
        q.pop();
        for(auto v : V[x])
            {
            sto[v]--;
            if(sto[v] == 0)
                q.push(v);
            }
        }
    if(il != n)
        {
        debug("cykl\n");
        cout<<-1<<endl;
        exit(0);
        }
    set <pair <PII, int> > ava;
    FOR(i, 1, n) {
        int v = per[i];
        if (r[v])
            low[v] = r[v];
        else
            low[v] = 1;
        for (auto c : Vi[v]) {
            debug("maxi(low[%d], low[%d] + 1\n", v, c);
            maxi(low[v], low[c] + 1);
        }
        debug("low[%d] = %d\n", v, low[v]);
    }
    FORD(i, n, 1) {
        int v = per[i];
        if (r[v])
            high[v] = r[v];
        else
            high[v] = k;
        for (auto c : V[v]) {
            debug("maxi(low[%d], low[%d] - 1\n", v, c);
            mini(high[v], high[c] - 1);
        }
        debug("high[%d] = %d\n", v, high[v]);
    }
    FOR(i, 1, n)
        if (high[i] < low[i]) err();

    vector <pair <int, int> > ranges[MXN];
        FOR(i, 1, n)
            ranges[high[i]].PB(MP(low[i], i));
    bool is[MXN];
    FOR(i, 1, n)    is[r[i]] = true;
    FORD(R, k, 1) {
        for (auto p : ranges[R]) {
            debug("insert range(%d, %d) from %d\n", p.first, R, p.second);
            ava.insert(MP(MP(p.first, R), p.second));
        }
        if (!is[R]) {
            debug("find %d\n", R);
            while (true) {
                if (ava.empty()) err();
                auto x = ava.end();
                x--;
                auto take = *x;
                ava.erase(x);
                debug("erase (%d, %d) from %d\n", take.f.f, take.f.s, take.s);
                if (take.f.f <= R && take.f.s >= R) {
                    r[take.s] = R;
                    break;
                }
            }
        }
    }
    FOR(i, 1, n) debug("%d ", r[i]);
    debug("\n");

    FORD(i, n, 1) {
        int v = per[i];
        if (r[v] == 0) {
            r[v] = k;
            for (auto c : V[v])
                mini(r[v], r[c] - 1);
        }
    }

    FOR(i, 1, n) printf("%d ", r[i]);
    printf("\n");
    }


#include<bits/stdc++.h>
#define PII pair<int,int>
#define f first
#define s second
#define VI vector<int>
#define LL long long
#define MP make_pair
#define LD long double
#define PB push_back
#define ALL(V) V.begin(),V.end()
#define abs(x) max((x),-(x))
#define PDD pair<LD,LD>
#define VPII vector< PII >
#define siz(V) ((int)V.size())
#define FOR(x, b, e)  for(int x=b;x<=(e);x++)
#define FORD(x, b, e) for(int x=b;x>=(e);x--)
#define REP(x, n)     for(int x=0;x<(n);x++)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#ifdef DEB
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif
using namespace std;
int n, m, k;
const int MXN = 2e5+5;
int r[MXN];
int perm[MXN];
#define per perm
VI V[MXN], Vi[MXN];
int sto[MXN];
int low[MXN], high[MXN];
void err() {
    printf("-1\n");
    exit(0);
}
int main()
    {
    scanf("%d%d%d", &n, &m, &k);
    FOR(i, 1, n)
        scanf("%d", &r[i]);

    REP(i, m)
        {
        int a, b;
        scanf("%d%d", &a, &b);
        V[b].PB(a);
        Vi[a].PB(b);
        sto[a]++;
        }
    queue<int> q;
    FOR(i, 1, n)
        if(sto[i] == 0)
            q.push(i);
    int il = 0;
    while(q.size())
        {
        int x;
        perm[++il] = x = q.front();
        q.pop();
        for(auto v : V[x])
            {
            sto[v]--;
            if(sto[v] == 0)
                q.push(v);
            }
        }
    if(il != n)
        {
        debug("cykl\n");
        cout<<-1<<endl;
        exit(0);
        }
    set <pair <PII, int> > ava;
    FOR(i, 1, n) {
        int v = per[i];
        if (r[v])
            low[v] = r[v];
        else
            low[v] = 1;
        for (auto c : Vi[v]) {
            debug("maxi(low[%d], low[%d] + 1\n", v, c);
            maxi(low[v], low[c] + 1);
        }
        debug("low[%d] = %d\n", v, low[v]);
    }
    FORD(i, n, 1) {
        int v = per[i];
        if (r[v])
            high[v] = r[v];
        else
            high[v] = k;
        for (auto c : V[v]) {
            debug("maxi(low[%d], low[%d] - 1\n", v, c);
            mini(high[v], high[c] - 1);
        }
        debug("high[%d] = %d\n", v, high[v]);
    }
    FOR(i, 1, n)
        if (high[i] < low[i]) err();

    vector <pair <int, int> > ranges[MXN];
        FOR(i, 1, n)
            ranges[high[i]].PB(MP(low[i], i));
    bool is[MXN];
    FOR(i, 1, n)    is[r[i]] = true;
    FORD(R, k, 1) {
        for (auto p : ranges[R]) {
            debug("insert range(%d, %d) from %d\n", p.first, R, p.second);
            ava.insert(MP(MP(p.first, R), p.second));
        }
        if (!is[R]) {
            debug("find %d\n", R);
            while (true) {
                if (ava.empty()) err();
                auto x = ava.end();
                x--;
                auto take = *x;
                ava.erase(x);
                debug("erase (%d, %d) from %d\n", take.f.f, take.f.s, take.s);
                if (take.f.f <= R && take.f.s >= R) {
                    r[take.s] = R;
                    break;
                }
            }
        }
    }
    FOR(i, 1, n) debug("%d ", r[i]);
    debug("\n");

    FORD(i, n, 1) {
        int v = per[i];
        if (r[v] == 0) {
            r[v] = k;
            for (auto c : V[v])
                mini(r[v], r[c] - 1);
        }
    }

    FOR(i, 1, n)
        {
        for(auto j : V[i])
            {
            if(r[i] > r[j])
                {
                puts("-1");
                exit(0);
                }
            }
        }

    FOR(i, 1, n) printf("%d ", r[i]);
    printf("\n");
    }


#include<bits/stdc++.h>
#define PII pair<int,int>
#define f first
#define s second
#define VI vector<int>
#define LL long long
#define MP make_pair
#define LD long double
#define PB push_back
#define ALL(V) V.begin(),V.end()
#define abs(x) max((x),-(x))
#define PDD pair<LD,LD>
#define VPII vector< PII >
#define siz(V) ((int)V.size())
#define FOR(x, b, e)  for(int x=b;x<=(e);x++)
#define FORD(x, b, e) for(int x=b;x>=(e);x--)
#define REP(x, n)     for(int x=0;x<(n);x++)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#ifdef DEB
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif
using namespace std;
int n, m, k;
const int MXN = 2e5+5;
int r[MXN];
int perm[MXN];
#define per perm
VI V[MXN], Vi[MXN];
int sto[MXN];
int low[MXN], high[MXN];
void err() {
    printf("-1\n");
    exit(0);
}
 bool is[MXN];
int main()
    {
    scanf("%d%d%d", &n, &m, &k);
    FOR(i, 1, n)
        scanf("%d", &r[i]);

    REP(i, m)
        {
        int a, b;
        scanf("%d%d", &a, &b);
        V[b].PB(a);
        Vi[a].PB(b);
        sto[a]++;
        }
    queue<int> q;
    FOR(i, 1, n)
        if(sto[i] == 0)
            q.push(i);
    int il = 0;
    while(q.size())
        {
        int x;
        perm[++il] = x = q.front();
        q.pop();
        for(auto v : V[x])
            {
            sto[v]--;
            if(sto[v] == 0)
                q.push(v);
            }
        }
    if(il != n)
        {
        debug("cykl\n");
        cout<<-1<<endl;
        exit(0);
        }
    set <pair <PII, int> > ava;
    FOR(i, 1, n) {
        int v = per[i];
        if (r[v])
            low[v] = r[v];
        else
            low[v] = 1;
        for (auto c : Vi[v]) {
            debug("maxi(low[%d], low[%d] + 1\n", v, c);
            maxi(low[v], low[c] + 1);
        }
        debug("low[%d] = %d\n", v, low[v]);
    }
    FORD(i, n, 1) {
        int v = per[i];
        if (r[v])
            high[v] = r[v];
        else
            high[v] = k;
        for (auto c : V[v]) {
            debug("maxi(low[%d], low[%d] - 1\n", v, c);
            mini(high[v], high[c] - 1);
        }
        debug("high[%d] = %d\n", v, high[v]);
    }
    FOR(i, 1, n)
        if (high[i] < low[i]) err();

    vector <pair <int, int> > ranges[MXN];
        FOR(i, 1, n)
            ranges[high[i]].PB(MP(low[i], i));

    FOR(i, 1, n)    is[r[i]] = true;
    FORD(R, k, 1) {
        for (auto p : ranges[R]) {
            debug("insert range(%d, %d) from %d\n", p.first, R, p.second);
            ava.insert(MP(MP(p.first, R), p.second));
        }
        if (!is[R]) {
            debug("find %d\n", R);
            while (true) {
                if (ava.empty()) err();
                auto x = ava.end();
                x--;
                auto take = *x;
                ava.erase(x);
                debug("erase (%d, %d) from %d\n", take.f.f, take.f.s, take.s);
                if (take.f.f <= R && take.f.s >= R) {
                    r[take.s] = R;
                    break;
                }
            }
        }
    }
    FOR(i, 1, n) debug("%d ", r[i]);
    debug("\n");

    FORD(i, n, 1) {
        int v = per[i];
        if (r[v] == 0) {
            r[v] = k;
            for (auto c : V[v])
                mini(r[v], r[c] - 1);
        }
    }

    FOR(i, 1, n)
        {
        for(auto j : V[i])
            {
            if(r[i] > r[j])
                {
                assert(false);
                puts("-1");
                exit(0);
                }
            }
        }

    FOR(i, 1, n) printf("%d ", r[i]);
    printf("\n");
    }


//be naame khodaa
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
#define F first
#define S second
#define pb push_back

inline int in(){ int x, y; y = scanf("%d", &x); return x; }

const int N = 300003;

int n, m, k;
vector <int> g[N], gr[N];
int to[N], from[N], mark[N], res[N], din[N], rem;
int x[N], r[N], y[N];

void out()
{
	cout << "-1\n";
	exit(0);
}

void dfs(int v)
{
	mark[v] = 1;
	for(int u : g[v])
		if(mark[u] == 1)
			out();
		else
		{
			if(!mark[u])
				dfs(u);
			from[v] = max(from[v], from[u]);
		}
	from[v]++;
	if(r[v] > 0)
	{
		if(from[v] > r[v])
			out();
		from[v] = r[v];
	}
	if(from[v] > k)
		out();
	mark[v] = 2;
}

bool seen[N];
set <pair<int, int>> ss, qs;

void updateRem()
{
	while(rem > 0 && seen[rem])
	{
		rem--;
		while(qs.size() && qs.rbegin()->first >= rem)
		{
			int v = qs.rbegin()->second;
			qs.erase({to[v], v});
			ss.insert({from[v], v});
		}
	}
}

void addSource(int v)
{
	int x = to[v];
	if(x >= rem)
		ss.insert({from[v], v});
	else
		qs.insert({x, v});
}

int main()
{
	cin >> n >> m >> k;
	for(int i = 0; i < n; i++)
		r[i] = in();
	for(int i = 0; i < m; i++)
	{
		x[i] = in() - 1;
		y[i] = in() - 1;
		g[x[i]].push_back(y[i]);
		gr[y[i]].push_back(x[i]);
		din[y[i]]++;
	}
	for(int i = 0; i < n; i++)
		if(!mark[i])
			dfs(i);
	rem = k;
	fill(to, to + n, k);
	for(int i = 0; i < n; i++)
	{
		if(r[i] > 0)
			to[i] = min(to[i], r[i]);
		if(!din[i])
			addSource(i);
	}
	for(int i = 0; i < n; i++)
	{
		if(ss.empty())
			out();
		int v = ss.rbegin()->second;
		ss.erase({from[v], v});
		assert(to[v] >= rem);
		if(r[v] > 0)
			res[v] = r[v];
		else
			res[v] = max(rem, from[v]);
//		cerr << v << " : " << rem << " " << to[v] << ", " << from[v] << " -> " << res[v] << endl;
		seen[res[v]] = true;
		updateRem();
		for(int u : g[v])
		{
			din[u]--;
			to[u] = min(to[u], res[v] - 1);
			if(to[u] < from[u])
				out();
			if(din[u] == 0)
				addSource(u);
		}
	}
//	cerr << " -> " << rem << endl;
	if(rem != 0)
		out();
	for(int i = 0; i < m; i++)
		if(res[x[i]] <= res[y[i]])
			out();
	for(int i = 0; i < n; i++)
		cout << res[i] << " ";
	cout << endl;
}


#include <bits/stdc++.h>
//#include "testing.cc"
#define maxn 50005
#define endl '\n'

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
struct Graph {
	VI IN, OUT;
	VVI adj;
	VVI radj;
	VI FV;
	VI UP, LO;
	Graph(int N):IN(N),OUT(N),adj(N),radj(N),FV(N,-1),UP(N,-1),LO(N,-1){}
	void addEdge(int u, int v){
		IN[v]++;
		OUT[u]++;
		adj[u].push_back(v);
		radj[v].push_back(u);
	}
	bool build(int K){
		VI VIS(adj.size());
		for (int i = 0; i < adj.size(); ++i) {
			if(!VIS[i] && hasCycle(i, VIS))
				return false;
		}
		for(int i = 0; i < adj.size(); ++i)
			if(UP[i] == -1 && !buildUpper(i, K))
				return false;
		for(int i = 0; i < adj.size(); ++i)
			if(LO[i] == -1 && !buildLower(i, K))
				return false;
		return true;
	}
	bool hasCycle(int u, VI &VIS){
		if(VIS[u] == 1)return true;
		VIS[u] = 1;
		for(int v : adj[u]){
			if(hasCycle(v, VIS))
				return true;
		}
		VIS[u] = 2;
		return false;
	}
	bool buildUpper(int u, int K){
		int lowest = FV[u] == -1 ? K : FV[u];
		for(int v : adj[u]){
			if(UP[v]==-1){
				if(!buildUpper(v, K))
					return false;
			}
			lowest = min(UP[v]-1, lowest);
		}
		if(FV[u] != -1 && FV[u] > lowest) {
			return false;//omg impossibnle
		}
		UP[u] = lowest;
		return true;
	}
	bool buildLower(int u, int K){
		int biggest = FV[u] == -1 ? 1 : FV[u];
		for(int v : radj[u]){
			if(LO[v]==-1){
				if(!buildLower(v, K))
					return false;
			}
			biggest = max(biggest, LO[v]+1);
		}
		if(FV[u] != -1 && FV[u] < biggest) {
			return false;//omg impossibnle
		}
		LO[u] = biggest;
		return true;
	}

};

struct Range {
	int s,e,id;
};

bool byEnd(Range a, Range b){
	return a.e < b.e;
}

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

	int N,M,K;
	cin >> N >> M >> K;
	Graph G(N);

	for (int i = 0; i < N; ++i) {
		int n;
		cin >> n;
		if(n == 0)continue;
		G.FV[i] = K-n+1;
	}
	for (int i = 0; i < M; ++i) {
		int u,v;
		cin >> u >> v;
		u--;v--;
		G.addEdge(u, v);
	}
	if(!G.build(K)){
		cout << -1 << endl;
		return 0;
	}
	vector<Range> R;
	for (int i = 0; i < N; ++i) {
		R.push_back({G.LO[i], G.UP[i], i});
		if(G.LO[i] > G.UP[i]){
			cout << -1 << endl;
			return 0;
		}
//		cout << G.LO[i] << " " << G.UP[i] << " " << G.FV[i] << endl;
	}
	set<int> S;
	for (int i = 1; i <= K; ++i) {
		S.insert(i);
	}
	sort(R.begin(), R.end(), byEnd);
	vector<int> ANS(N);
	for (int i = 0; i < R.size(); ++i) {
		auto l = S.lower_bound(R[i].s);
		if(l == S.end() || *l > R[i].e){
			ANS[R[i].id] = R[i].e;
		}else{
			ANS[R[i].id] = *l;
			S.erase(*l);
		}
	}
	if(S.size()){
		cout << -1 << endl;
		return 0;
	}
	for(int v : ANS){
		cout << K-v+1 << " ";
	}
	cout << endl;

    return 0;
}


#include <bits/stdc++.h>
//#include "testing.cc"
#define maxn 50005
#define endl '\n'

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
struct Graph {
	VVI adj;
	VVI radj;
	VI FV;
	VI UP, LO;
	Graph(int N):adj(N),radj(N),FV(N,-1),UP(N,-1),LO(N,-1){}
	void addEdge(int u, int v){
		adj[u].push_back(v);
		radj[v].push_back(u);
	}
	bool build(int K){
		VI VIS(adj.size());
		for (int i = 0; i < adj.size(); ++i) {
			if(!VIS[i] && hasCycle(i, VIS))
				return false;
		}
		for(int i = 0; i < adj.size(); ++i)
			if(UP[i] == -1 && !buildUpper(i, K))
				return false;
		for(int i = 0; i < adj.size(); ++i)
			if(LO[i] == -1 && !buildLower(i, K))
				return false;
		return true;
	}
	bool hasCycle(int u, VI &VIS){
		if(VIS[u] == 2)return false;
		if(VIS[u] == 1)return true;
		VIS[u] = 1;
		for(int v : adj[u]){
			if(hasCycle(v, VIS))
				return true;
		}
		VIS[u] = 2;
		return false;
	}
	bool buildUpper(int u, int K){
		int lowest = FV[u] == -1 ? K : FV[u];
		for(int v : adj[u]){
			if(UP[v]==-1){
				if(!buildUpper(v, K))
					return false;
			}
			lowest = min(UP[v]-1, lowest);
		}
		if(FV[u] != -1 && FV[u] > lowest) {
			return false;//omg impossibnle
		}
		UP[u] = lowest;
		return true;
	}
	bool buildLower(int u, int K){
		int biggest = FV[u] == -1 ? 1 : FV[u];
		for(int v : radj[u]){
			if(LO[v]==-1){
				if(!buildLower(v, K))
					return false;
			}
			biggest = max(biggest, LO[v]+1);
		}
		if(FV[u] != -1 && FV[u] < biggest) {
			return false;//omg impossibnle
		}
		LO[u] = biggest;
		return true;
	}

};

struct Range {
	int s,e,id;
};

bool byEnd(Range a, Range b){
	return a.e < b.e;
}

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

	int N,M,K;
	cin >> N >> M >> K;
	Graph G(N);

	for (int i = 0; i < N; ++i) {
		int n;
		cin >> n;
		if(n == 0)continue;
		G.FV[i] = K-n+1;
	}
	for (int i = 0; i < M; ++i) {
		int u,v;
		cin >> u >> v;
		u--;v--;
		G.addEdge(u, v);
	}
	if(!G.build(K)){
		cout << -1 << endl;
		return 0;
	}
	vector<Range> R;
	for (int i = 0; i < N; ++i) {
		R.push_back({G.LO[i], G.UP[i], i});
		if(G.LO[i] > G.UP[i]){
			cout << -1 << endl;
			return 0;
		}
//		cout << G.LO[i] << " " << G.UP[i] << " " << G.FV[i] << endl;
	}
	set<int> S;
	for (int i = 1; i <= K; ++i) {
		S.insert(i);
	}
	sort(R.begin(), R.end(), byEnd);
	vector<int> ANS(N);
	for (int i = 0; i < R.size(); ++i) {
		auto l = S.lower_bound(R[i].s);
		if(l == S.end() || *l > R[i].e){
			ANS[R[i].id] = R[i].e;
		}else{
			ANS[R[i].id] = *l;
			S.erase(*l);
		}
	}
	if(S.size()){
		cout << -1 << endl;
		return 0;
	}
	for(int v : ANS){
		cout << K-v+1 << " ";
	}
	cout << endl;

    return 0;
}


#include <bits/stdc++.h>
//#include "testing.cc"
#define maxn 50005
#define endl '\n'

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
struct Graph {
	VI IN, OUT;
	VVI adj;
	VVI radj;
	VI FV;
	VI UP, LO;
	Graph(int N):IN(N),OUT(N),adj(N),radj(N),FV(N,-1),UP(N,-1),LO(N,-1){}
	void addEdge(int u, int v){
		IN[v]++;
		OUT[u]++;
		adj[u].push_back(v);
		radj[v].push_back(u);
	}
	bool build(int K){
		VI VIS(adj.size());
		for (int i = 0; i < adj.size(); ++i) {
			if(!VIS[i] && hasCycle(i, VIS))
				return false;
		}
		for(int i = 0; i < adj.size(); ++i)
			if(UP[i] == -1 && !buildUpper(i, K))
				return false;
		for(int i = 0; i < adj.size(); ++i)
			if(LO[i] == -1 && !buildLower(i, K))
				return false;
		return true;
	}
	bool hasCycle(int u, VI &VIS){
		if(VIS[u] == 1)return true;
		VIS[u] = 1;
		for(int v : adj[u]){
			if(hasCycle(v, VIS))
				return true;
		}
		VIS[u] = 2;
		return false;
	}
	bool buildUpper(int u, int K){
		int lowest = FV[u] == -1 ? K : FV[u];
		for(int v : adj[u]){
			if(UP[v]==-1){
				if(!buildUpper(v, K))
					return false;
			}
			lowest = min(UP[v]-1, lowest);
		}
		if(FV[u] != -1 && FV[u] > lowest) {
			return false;//omg impossibnle
		}
		UP[u] = lowest;
		return true;
	}
	bool buildLower(int u, int K){
		int biggest = FV[u] == -1 ? 1 : FV[u];
		for(int v : radj[u]){
			if(UP[v]==-1){
				if(buildLower(v, K))
					return false;
			}
			biggest = max(biggest, LO[v]+1);
		}
		if(FV[u] != -1 && FV[u] < biggest) {
			return false;//omg impossibnle
		}
		LO[u] = biggest;
		return true;
	}

};

struct Range {
	int s,e,id;
};

bool byEnd(Range a, Range b){
	return a.e < b.e;
}

int main() {

	int N,M,K;
	cin >> N >> M >> K;
	Graph G(N);

	for (int i = 0; i < N; ++i) {
		int n;
		cin >> n;
		if(n == 0)continue;
		G.FV[i] = K-n+1;
	}
	for (int i = 0; i < M; ++i) {
		int u,v;
		cin >> u >> v;
		u--;v--;
		G.addEdge(u, v);
	}
	if(!G.build(K)){
		cout << -1 << endl;
		return 0;
	}
	vector<Range> R;
	for (int i = 0; i < N; ++i) {
		R.push_back({G.LO[i], G.UP[i], i});
		if(G.LO[i] > G.UP[i]){
			cout << -1 << endl;
			return 0;
		}
//		cout << G.LO[i] << " " << G.UP[i] << " " << G.FV[i] << endl;
	}
	set<int> S;
	for (int i = 1; i <= K; ++i) {
		S.insert(i);
	}
	sort(R.begin(), R.end(), byEnd);
	vector<int> ANS(N);
	for (int i = 0; i < R.size(); ++i) {
		auto l = S.lower_bound(R[i].s);
		if(l == S.end() || *l > R[i].e){
			ANS[R[i].id] = R[i].e;
		}else{
			ANS[R[i].id] = *l;
			S.erase(*l);
		}
	}
	if(S.size()){
		cout << -1 << endl;
		return 0;
	}
	for(int v : ANS){
		cout << K-v+1 << " ";
	}
	cout << endl;

    return 0;
}


#include <bits/stdc++.h>
//#include "testing.cc"
#define maxn 50005
#define endl '\n'

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
struct Graph {
	VI IN, OUT;
	VVI adj;
	VVI radj;
	VI FV;
	VI UP, LO;
	Graph(int N):IN(N),OUT(N),adj(N),radj(N),FV(N,-1),UP(N,-1),LO(N,-1){}
	void addEdge(int u, int v){
		IN[v]++;
		OUT[u]++;
		adj[u].push_back(v);
		radj[v].push_back(u);
	}
	bool build(int K){
		VI VIS(adj.size());
		for (int i = 0; i < adj.size(); ++i) {
			if(!VIS[i] && hasCycle(i, VIS))
				return false;
		}
		for(int i = 0; i < adj.size(); ++i)
			if(UP[i] == -1 && !buildUpper(i, K))
				return false;
		for(int i = 0; i < adj.size(); ++i)
			if(LO[i] == -1 && !buildLower(i, K))
				return false;
		return true;
	}
	bool hasCycle(int u, VI &VIS){
		if(VIS[u] == 1)return true;
		VIS[u] = 1;
		for(int v : adj[u]){
			if(hasCycle(v, VIS))
				return true;
		}
		VIS[u] = 2;
		return false;
	}
	bool buildUpper(int u, int K){
		int lowest = FV[u] == -1 ? K : FV[u];
		for(int v : adj[u]){
			if(UP[v]==-1){
				if(!buildUpper(v, K))
					return false;
			}
			lowest = min(UP[v]-1, lowest);
		}
		if(FV[u] != -1 && FV[u] > lowest) {
			return false;//omg impossibnle
		}
		UP[u] = lowest;
		return true;
	}
	bool buildLower(int u, int K){
		int biggest = FV[u] == -1 ? 1 : FV[u];
		for(int v : radj[u]){
			if(LO[v]==-1){
				if(!buildLower(v, K))
					return false;
			}
			biggest = max(biggest, LO[v]+1);
		}
		if(FV[u] != -1 && FV[u] < biggest) {
			return false;//omg impossibnle
		}
		LO[u] = biggest;
		return true;
	}

};

struct Range {
	int s,e,id;
};

bool byEnd(Range a, Range b){
	return a.e < b.e;
}

int main() {

	int N,M,K;
	cin >> N >> M >> K;
	Graph G(N);

	for (int i = 0; i < N; ++i) {
		int n;
		cin >> n;
		if(n == 0)continue;
		G.FV[i] = K-n+1;
	}
	for (int i = 0; i < M; ++i) {
		int u,v;
		cin >> u >> v;
		u--;v--;
		G.addEdge(u, v);
	}
	if(!G.build(K)){
		cout << -1 << endl;
		return 0;
	}
	vector<Range> R;
	for (int i = 0; i < N; ++i) {
		R.push_back({G.LO[i], G.UP[i], i});
		if(G.LO[i] > G.UP[i]){
			cout << -1 << endl;
			return 0;
		}
//		cout << G.LO[i] << " " << G.UP[i] << " " << G.FV[i] << endl;
	}
	set<int> S;
	for (int i = 1; i <= K; ++i) {
		S.insert(i);
	}
	sort(R.begin(), R.end(), byEnd);
	vector<int> ANS(N);
	for (int i = 0; i < R.size(); ++i) {
		auto l = S.lower_bound(R[i].s);
		if(l == S.end() || *l > R[i].e){
			ANS[R[i].id] = R[i].e;
		}else{
			ANS[R[i].id] = *l;
			S.erase(*l);
		}
	}
	if(S.size()){
		cout << -1 << endl;
		return 0;
	}
	for(int v : ANS){
		cout << K-v+1 << " ";
	}
	cout << endl;

    return 0;
}


#include <bits/stdc++.h>
//#include "testing.cc"
#define maxn 50005
#define endl '\n'

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
struct Graph {
	VI IN, OUT;
	VVI adj;
	VVI radj;
	VI FV;
	VI UP, LO;
	Graph(int N):IN(N),OUT(N),adj(N),radj(N),FV(N,-1),UP(N,-1),LO(N,-1){}
	void addEdge(int u, int v){
		IN[v]++;
		OUT[u]++;
		adj[u].push_back(v);
		radj[v].push_back(u);
	}
	bool build(int K){
		VI VIS(adj.size());
		for (int i = 0; i < adj.size(); ++i) {
			if(!VIS[i] && hasCycle(i, VIS))
				return false;
		}
		for(int i = 0; i < adj.size(); ++i)
			if(UP[i] == -1 && !buildUpper(i, K))
				return false;
		for(int i = 0; i < adj.size(); ++i)
			if(LO[i] == -1 && !buildLower(i, K))
				return false;
		return true;
	}
	bool hasCycle(int u, VI &VIS){
		if(VIS[u] == 1)return true;
		VIS[u] = 1;
		for(int v : adj[u]){
			if(hasCycle(v, VIS))
				return true;
		}
		VIS[u] = 2;
		return false;
	}
	bool buildUpper(int u, int K){
		int lowest = FV[u] == -1 ? K : FV[u];
		for(int v : adj[u]){
			if(UP[v]==-1){
				if(!buildUpper(v, K))
					return false;
			}
			lowest = min(UP[v]-1, lowest);
		}
		if(FV[u] != -1 && FV[u] > lowest) {
			return false;//omg impossibnle
		}
		UP[u] = lowest;
		return true;
	}
	bool buildLower(int u, int K){
		int biggest = FV[u] == -1 ? 1 : FV[u];
		for(int v : radj[u]){
			if(UP[v]==-1){
				if(buildLower(v, K))
					return false;
			}
			biggest = max(biggest, LO[v]+1);
		}
		if(FV[u] != -1 && FV[u] < biggest) {
			return false;//omg impossibnle
		}
		LO[u] = biggest;
		return true;
	}

};

struct Range {
	int s,e,id;
};

bool byEnd(Range a, Range b){
	return a.e < b.e;
}

int main() {

	int N,M,K;
	cin >> N >> M >> K;
	Graph G(N);

	for (int i = 0; i < N; ++i) {
		int n;
		cin >> n;
		if(n == 0)continue;
		G.FV[i] = K-n+1;
	}
	for (int i = 0; i < M; ++i) {
		int u,v;
		cin >> u >> v;
		u--;v--;
		G.addEdge(u, v);
	}
	if(!G.build(K)){
		cout << -1 << endl;
		return 0;
	}
	vector<Range> R;
	for (int i = 0; i < N; ++i) {
		R.push_back({G.LO[i], G.UP[i], i});
//		cout << G.LO[i] << " " << G.UP[i] << " " << G.FV[i] << endl;
	}
	set<int> S;
	for (int i = 1; i <= K; ++i) {
		S.insert(i);
	}
	sort(R.begin(), R.end(), byEnd);
	vector<int> ANS(N);
	for (int i = 0; i < R.size(); ++i) {
		auto l = S.lower_bound(R[i].s);
		if(l == S.end() || *l > R[i].e){
			ANS[R[i].id] = R[i].e;
		}else{
			ANS[R[i].id] = *l;
			S.erase(*l);
		}
	}
	if(S.size()){
		cout << -1 << endl;
		return 0;
	}
	for(int v : ANS){
		cout << K-v+1 << " ";
	}
	cout << endl;

    return 0;
}


#include <bits/stdc++.h>

#define st first
#define nd second
#define all(x) (x).begin(), (x).end()

using namespace std;
using namespace placeholders;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <class T> void mini(T &l, T r){l = min(l, r);}
template <class T> void maxi(T &l, T r){l = max(l, r);}

template <class TH> void _dbg(const char *sdbg, TH h){cerr << sdbg << "=" << h << "\n";}
template <class TH, class ...TA> void _dbg(const char *sdbg, TH h, TA... a){
	while (*sdbg != ',') cerr << *sdbg++; cerr << "=" << h << ","; _dbg(sdbg + 1, a...);
}
template <class T> ostream &operator <<(ostream &os, vector<T> V){
	os << "["; for (auto vv: V) os << vv << ","; return os << "]";
}
template <class L, class R> ostream &operator <<(ostream &os, pair<L, R> P){
	return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef SFIC
	#define eput(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
	#define eput(...) 218
#endif

const int M = 2E5 + 10, N = M;

int n, m, K;
int rk[M], lb[M], ub[M], deg[M];
vector<int> E[M], b, c[N];
int h[M];

int main(){
	scanf("%d%d%d", &n, &m, &K);
	for (int i = 1; i <= n; ++i){
		scanf("%d", rk + i);
		if (rk[i])
			lb[i] = ub[i] = rk[i];
		else
			lb[i] = 1, ub[i] = K;
	}
	for (int i = 0; i < m; ++i){
		int u, v;
		scanf("%d%d", &u, &v);
		E[u].push_back(v);
		++deg[v];
	}

	queue<int> Q;
	for (int i = 1; i <= n; ++i)
		if (deg[i] == 0)
			Q.push(i);
	while (!Q.empty()){
		int u = Q.front();
		Q.pop();
		b.push_back(u);

		for (auto &v: E[u])
			if (--deg[v] == 0)
				Q.push(v);
	}
	if (b.size() < n){
		puts("-1");
		return 0;
	}

	for (int i = 0; i < n; ++i){
		int u = b[i];
		for (auto &v: E[u])
			ub[v] = min(ub[v], ub[u] - 1);
	}
	for (int i = n - 1; i >= 0; --i){
		int u = b[i];
		for (auto &v: E[u])
			lb[u] = max(lb[u], lb[v] + 1);
	}
	for (int i = 1; i <= n; ++i){
		if (lb[i] > ub[i]){
			puts("-1");
			return 0;
		}
		c[ub[i]].push_back(i);
	}

	priority_queue<pii> Q1;
	for (int i = K; i >= 1; --i){
		for (auto &t: c[i])
			Q1.emplace(lb[t], t);
		if (Q1.empty()){
			puts("-1");
			return 0;
		}

		int u = Q1.top().nd;
		rk[u] = i;
		Q1.pop();
		for (; !Q1.empty() && Q1.top().st == i; Q1.pop())
			rk[Q1.top().nd] = i;
	}
	for (int i = 1; i <= n; ++i)
		printf("%d%c", rk[i], "\n "[i < n]);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int N = 200001, inf = 1e9;
int mn[N], mx[N];
vector<int> g[N];
vector<int> rg[N];
vector<int> vec;
int col[N];
vector<pair<int, int>> pr[N];
int n, m, k;

void dfs(int v)
{
	if(col[v] == 2) return;
	if(col[v] == 1)
	{
		puts("-1");
		exit(0);
	}
	col[v] = 1;
	for(auto u: g[v])
		dfs(u);
	col[v] = 2;
	vec.push_back(v);
}

void update()
{
	for(int v: vec)
		for(int u: g[v])
			mn[v] = max(mn[v], mn[u] + 1);
	reverse(vec.begin(), vec.end());
	for(int v: vec)
		for(int u: rg[v])
			mx[v] = min(mx[v], mx[u] - 1);
	reverse(vec.begin(), vec.end());
}

int main()
{
	scanf("%d %d %d", &n, &m, &k);
	for(int i = 1; i <= n; i++)
	{
		int r;
		scanf("%d", &r);
		if(r == 0)
		{
			mn[i] = 1;
			mx[i] = k;
		}
		else mn[i] = mx[i] = r;
	}
	while(m--)
	{
		int x, y;
		scanf("%d %d", &x, &y);
		g[x].push_back(y);
		rg[y].push_back(x);
	}
	for(int i = 1; i <= n; i++)
		dfs(i);
	update();
	if(*min_element(mx + 1, mx + n + 1) < 1 || *max_element(mn + 1, mn + n + 1) > k)
	{
		puts("-1");
		return 0;
	}
	for(int i = 1; i <= n; i++)
		pr[mn[i]].emplace_back(mx[i], i);
	priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
	for(int i = 1; i <= k; i++)
	{
		for(auto p: pr[i]) pq.push(p);
		while(!pq.empty() && pq.top().first < i) pq.pop();
		if(pq.empty())
		{
			puts("-1");
			return 0;
		}
		auto p = pq.top();
		pq.pop();
		mn[p.second] = mx[p.second] = i;
	}
	update();
	for(int i = 1; i <= n; i++)
		if(mn[i] > mx[i])
		{
			puts("-1");
			return 0;
		}
	for(int i = 1; i <= n; i++)
		printf("%d ", mn[i]);
	puts("");
}


#include <bits/stdc++.h>
using namespace std;

const int N = 200001, inf = 1e9;
int mn[N], mx[N];
vector<int> g[N];
vector<int> rg[N];
vector<int> vec;
int col[N];
vector<pair<int, int>> pr[N];
int n, m, k;

void dfs(int v)
{
	if(col[v] == 2) return;
	if(col[v] == 1)
	{
		puts("-1");
		exit(0);
	}
	col[v] = 1;
	for(auto u: g[v])
		dfs(u);
	col[v] = 2;
	vec.push_back(v);
}

void update()
{
	for(int v: vec)
		for(int u: g[v])
			mn[v] = max(mn[v], mn[u] + 1);
	reverse(vec.begin(), vec.end());
	for(int v: vec)
		for(int u: rg[v])
			mx[v] = min(mx[v], mx[u] - 1);
	reverse(vec.begin(), vec.end());
}

int main()
{
	scanf("%d %d %d", &n, &m, &k);
	for(int i = 1; i <= n; i++)
	{
		int r;
		scanf("%d", &r);
		if(r == 0)
		{
			mn[i] = 1;
			mx[i] = k;
		}
		else mn[i] = mx[i] = r;
	}
	while(m--)
	{
		int x, y;
		scanf("%d %d", &x, &y);
		g[x].push_back(y);
		rg[y].push_back(x);
	}
	for(int i = 1; i <= n; i++)
		dfs(i);
	update();
	if(*min_element(mx + 1, mx + n + 1) < 1 || *max_element(mn + 1, mn + n + 1) > k)
	{
		puts("-1");
		return 0;
	}
	for(int i = 1; i <= n; i++)
		pr[mn[i]].emplace_back(mx[i], i);
	priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
	for(int i = 1; i <= k; i++)
	{
		for(auto p: pr[i]) pq.push(p);
		while(!pq.empty() && pq.top().first < i) pq.pop();
		if(pq.empty())
		{
			puts("-1");
			return 0;
		}
		auto p = pq.top();
		pq.pop();
		mn[p.second] = mx[p.second] = i;
	}
	update();
	for(int i = 1; i <= n; i++)
		printf("%d ", mn[i]);
	puts("");
}


#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
//#include <unordered_map>
//#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define szz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

//typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;
typedef tuple<int, int, int> t3;
#define rep(i, n) for(int i=0;i<n;i++)

int IT_MAX = 1 << 18;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x1f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-12;

vector <int> conn[200050];
vector <int> rconn[200050];
int inc[200050];
int mx[200050];
int ans[200050];

int mn[200050];
set <pii> Sx1;
set <pii> Sx2;
vector <int> Vl;
void propagate() {
	while (!Vl.empty()) {
		int t = Vl.back();
		Vl.pop_back();
		for (auto it : rconn[t]) {
			mn[it] = max(mn[it], ans[t] + 1);
			if (--inc[it] == 0) Sx2.emplace(mn[it], it);
		}
	}
}
int main() {
	int N, M, K, i, j;
	scanf("%d %d %d", &N, &M, &K);
	for (i = 1; i <= N; i++) {
		int t;
		scanf("%d", &t);
		ans[i] = t;
		if (t != 0) mx[i] = mn[i] = t;
		else {
			mn[i] = 1;
			mx[i] = K;
		}
	}
	for (i = 1; i <= M; i++) {
		int t1, t2;
		scanf("%d %d", &t1, &t2);
		conn[t1].push_back(t2);
		rconn[t2].push_back(t1);
	}

	for (i = 1; i <= N; i++) inc[i] = rconn[i].size();
	vector <int> Vu;
	for (i = 1; i <= N; i++) if (!inc[i]) Vu.push_back(i);
	for (i = 0; i < Vu.size(); i++) {
		for (auto it : conn[Vu[i]]) {
			mx[it] = min(mx[it], mx[Vu[i]] - 1);
			if (--inc[it] == 0) Vu.push_back(it);
		}
	}
	if (Vu.size() != N) return !printf("-1\n");
	Vu.clear();

	for (i = 1; i <= N; i++) {
		if (mx[i] <= 0) return !printf("-1\n");
		if (ans[i] && ans[i] > mx[i]) return !printf("-1\n");
	}

	for (i = 1; i <= N; i++) inc[i] = conn[i].size();
	for (i = 1; i <= N; i++) if (inc[i] == 0) Sx2.emplace(mn[i], i);

	for (i = 1; i <= K; i++) {
		while (!Sx2.empty()) {
			if (Sx2.begin()->first != i) break;
			int t = Sx2.begin()->second;
			Sx2.erase(Sx2.begin());
			Sx1.emplace(mx[t], t);
		}
		if (Sx1.empty()) return !printf("-1\n");

		auto it = Sx1.begin();
		Vl.push_back(it->second);
		ans[it->second] = i;
		Sx1.erase(it);
		while (!Sx1.empty()) {
			if (Sx1.begin()->first != i) break;
			int t = Sx1.begin()->second;
			Sx1.erase(Sx1.begin());
			ans[t] = i;
			Vl.push_back(t);
		}
		propagate();
	}
	for (i = 1; i <= N; i++) printf("%d ", ans[i]);
	return !printf("\n");
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ii pair<int,int>
const int N=200001;
const int oo=1000000000;
int n,m,k,indeg[N],rdeg[N],fr[N],rankk[N],ans[N],is[N],al[N];
vector<int> g[N], p[N];
void no(){
	cout<<-1<<endl;
	exit(0);
}
int main(){
	cin>>n>>m>>k;
	if(k>n)
		no();
	for(int i=0; i<n; ++i){
		scanf("%d",&rankk[i]);
		if(rankk[i])
			al[i]=1;
	}
	for(int a,b,i=0; i<m; ++i){
		scanf("%d%d",&a,&b);
		--a;--b;
		++indeg[b];
		++rdeg[a];
		g[a].pb(b);
		p[b].pb(a);
	}
	queue<int> q;
	for(int i=0; i<n; ++i)
		if(!indeg[i])
			q.push(i);
	int ls=k,cttt=0;
	while(!q.empty()){
		int u=q.front();
		q.pop();
		++cttt;
		int rk=rankk[u];
		if(!rk){
			rk=k;
			for(int i=0; i<p[u].size(); ++i)
				rk=min(rk, rankk[p[u][i]]-1);
		}
		rankk[u]=rk;
		is[rk]=1;
		ls=min(ls,rk);
		for(int i=0; i<g[u].size(); ++i){
			if(rankk[g[u][i]]>rk)
				no();
			if(!--indeg[g[u][i]])
				q.push(g[u][i]);
		}
	}
	if(cttt<n || ls<1)
		no();
	set<int> st;
	for(int i=1; i<=k; ++i)
		if(!is[i])
			st.insert(i);
	priority_queue<ii> qq;
	for(int i=0; i<n; ++i){
		++fr[rankk[i]];
		if(!rdeg[i])
			qq.push(ii(-rankk[i],i));
	}
	while(!qq.empty()&&!st.empty()){
		int u=qq.top().second;
		qq.pop();
		if(al[u])continue;
		int d=*st.begin();
		if(rankk[u]<d)continue;
		st.erase(st.begin());
		if(!--fr[rankk[u]])
			st.insert(rankk[u]);
		++fr[d];
		rankk[u]=d;
		for(int i=0; i<p[u].size(); ++i)
			if(!--rdeg[p[u][i]])
				qq.push(ii(-rankk[p[u][i]],p[u][i]));
	}
	if(st.size())
		no();
	for(int i=0; i<n; ++i)
		printf("%d ", rankk[i]);
	puts("");
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ii pair<int,int>
const int N=200001;
const int oo=1000000000;
int n,m,k,indeg[N],rdeg[N],fr[N],rankk[N],ans[N],is[N],al[N];
vector<int> g[N], p[N];
void no(){
	cout<<-1<<endl;
	exit(0);
}
int main(){
	cin>>n>>m>>k;
	if(k>n)
		no();
	for(int i=0; i<n; ++i){
		scanf("%d",&rankk[i]);
		if(rankk[i])
			al[i]=1;
	}
	for(int a,b,i=0; i<m; ++i){
		scanf("%d%d",&a,&b);
		--a;--b;
		++indeg[b];
		++rdeg[a];
		g[a].pb(b);
		p[b].pb(a);
	}
	queue<int> q;
	for(int i=0; i<n; ++i)
		if(!indeg[i])
			q.push(i);
	int ls=k,cttt=0;
	while(!q.empty()){
		int u=q.front();
		q.pop();
		++cttt;
		int rk=rankk[u];
		if(!rk){
			rk=k;
			for(int i=0; i<p[u].size(); ++i)
				rk=min(rk, rankk[p[u][i]]-1);
		}
		rankk[u]=rk;
		//cout<<u+1<<" "<<rk<<endl;
		is[rk]=1;
		ls=min(ls,rk);
		for(int i=0; i<g[u].size(); ++i){
			if(rankk[g[u][i]]>rk)
				no();
			if(!--indeg[g[u][i]])
				q.push(g[u][i]);
		}
	}
	if(cttt<n || ls<1)
		no();
	set<int> st;
	for(int i=1; i<=k; ++i)
		if(!is[i])
			st.insert(i);
	for(int i=0; i<n; ++i){
		++fr[rankk[i]];
		if(!rdeg[i])
			q.push(i);
	}
	while(!q.empty()&&!st.empty()){
		int u=q.front();
		q.pop();
		if(al[u])continue;
		int d=*st.begin();
		st.erase(st.begin());
		if(!--fr[rankk[u]])
			st.insert(rankk[u]);
		++fr[d];
		rankk[u]=d;
		for(int i=0; i<p[u].size(); ++i)
			if(!--rdeg[p[u][i]])
				q.push(p[u][i]);
	}
	if(st.size())
		no();
	for(int i=0; i<n; ++i)
		printf("%d ", rankk[i]);
	puts("");
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ii pair<int,int>
const int N=200001;
const int oo=1000000000;
int n,m,k,indeg[N],rankk[N],ans[N],is[N];
vector<int> g[N], p[N];
void no(){
	cout<<-1<<endl;
	exit(0);
}
int main(){
	cin>>n>>m>>k;
	if(k>n)
		no();
	for(int i=0; i<n; ++i)
		scanf("%d",&rankk[i]);
	for(int a,b,i=0; i<m; ++i){
		scanf("%d%d",&a,&b);
		--a;--b;
		++indeg[b];
		g[a].pb(b);
		p[b].pb(a);
	}
	queue<int> q;
	for(int i=0; i<n; ++i)
		if(!indeg[i])
			q.push(i);
	vector<ii> v;
	int ls=k;
	while(!q.empty()){
		int u=q.front();
		q.pop();
		int rk=rankk[u];
		if(!rk){
			rk=k;
			for(int i=0; i<p[u].size(); ++i)
				rk=min(rk, rankk[p[u][i]]-1);
		}
		rankk[u]=rk;
		//cout<<u+1<<" "<<rk<<endl;
		is[rk]=1;
		ls=min(ls,rk);
		v.pb(ii(rk,u));
		for(int i=0; i<g[u].size(); ++i){
			if(rankk[g[u][i]]>rk)
				no();
			if(!--indeg[g[u][i]])
				q.push(g[u][i]);
		}
	}
	if(v.size()<n || ls<1)
		no();
	priority_queue<int> pq;
	set<int> till;
	for(int i=1; i<=k; ++i)
		if(!is[i])
			pq.push(i);
	sort(v.rbegin(), v.rend());
	for(int i=0; i<v.size(); ++i){
		//cout<<v[i].first<<" "<<v[i].second<<endl;
		while(!till.empty() && v[i].first<*till.begin())
			till.erase(till.begin());
		v[i].first-=till.size();
		if(i&&v[i].first==v[i-1].first && pq.size()){
			int d=pq.top();
			if(d>v[i].first)
				no();
			pq.pop();
			till.insert(d);
			--v[i].first;
		}
		ans[v[i].second]=v[i].first;
	}
	memset(is,0,sizeof(is));
	for(int i=0; i<n; ++i)
		is[ans[i]]=1;
	for(int i=1; i<=k; ++i)
		if(!is[i])
			no();
	for(int i=0; i<n; ++i)
		printf("%d ", ans[i]);
	puts("");
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ii pair<int,int>
const int N=200001;
const int oo=1000000000;
int n,m,k,indeg[N],rdeg[N],fr[N],rankk[N],ans[N],is[N],al[N];
vector<int> g[N], p[N];
void no(){
	cout<<-1<<endl;
	exit(0);
}
int main(){
	cin>>n>>m>>k;
	if(k>n)
		no();
	for(int i=0; i<n; ++i){
		scanf("%d",&rankk[i]);
		if(rankk[i])
			al[i]=1;
	}
	for(int a,b,i=0; i<m; ++i){
		scanf("%d%d",&a,&b);
		--a;--b;
		++indeg[b];
		++rdeg[a];
		g[a].pb(b);
		p[b].pb(a);
	}
	queue<int> q;
	for(int i=0; i<n; ++i)
		if(!indeg[i])
			q.push(i);
	int ls=k,cttt=0;
	while(!q.empty()){
		int u=q.front();
		q.pop();
		++cttt;
		int rk=rankk[u];
		if(!rk){
			rk=k;
			for(int i=0; i<p[u].size(); ++i)
				rk=min(rk, rankk[p[u][i]]-1);
		}
		rankk[u]=rk;
		is[rk]=1;
		ls=min(ls,rk);
		for(int i=0; i<g[u].size(); ++i){
			if(rankk[g[u][i]]>rk)
				no();
			if(!--indeg[g[u][i]])
				q.push(g[u][i]);
		}
	}
	if(cttt<n || ls<1)
		no();
	set<int> st;
	set<ii> oth;
	for(int i=1; i<=k; ++i)
		if(!is[i])
			st.insert(i);
	priority_queue<ii> qq;
	for(int i=0; i<n; ++i){
		++fr[rankk[i]];
		if(!rdeg[i])
			qq.push(ii(-rankk[i],i));
	}
	while(!qq.empty()&&!st.empty()){
		int u=qq.top().second;
		qq.pop();
		bool fff=1;
		int d=*st.begin();
		if(!al[u] && rankk[u]>d){
			st.erase(st.begin());
			if(!--fr[rankk[u]])
				st.insert(rankk[u]);
			++fr[d];
			rankk[u]=d;
		}else if(al[u] && rankk[u]>d)
			oth.insert(ii(rankk[u],u)),fff=0;
		if(fff)
		for(int i=0; i<p[u].size(); ++i)
			if(!--rdeg[p[u][i]])
				qq.push(ii(-rankk[p[u][i]],p[u][i]));
		while(!oth.empty() && !st.empty() && oth.begin()->first<*st.begin()){
			qq.push(ii(-oth.begin()->first, oth.begin()->second));
			oth.erase(oth.begin());
		}
	}
	if(st.size())
		no();
	for(int i=0; i<n; ++i)
		printf("%d ", rankk[i]);
	puts("");
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ii pair<int,int>
const int N=200001;
const int oo=1000000000;
int n,m,k,indeg[N],rdeg[N],fr[N],rankk[N],ans[N],is[N],al[N];
vector<int> g[N], p[N];
void no(){
	cout<<-1<<endl;
	exit(0);
}
int main(){
	cin>>n>>m>>k;
	if(k>n)
		no();
	for(int i=0; i<n; ++i){
		scanf("%d",&rankk[i]);
		if(rankk[i])
			al[i]=1;
	}
	for(int a,b,i=0; i<m; ++i){
		scanf("%d%d",&a,&b);
		--a;--b;
		++indeg[b];
		++rdeg[a];
		g[a].pb(b);
		p[b].pb(a);
	}
	queue<int> q;
	for(int i=0; i<n; ++i)
		if(!indeg[i])
			q.push(i);
	int ls=k,cttt=0;
	while(!q.empty()){
		int u=q.front();
		q.pop();
		++cttt;
		int rk=rankk[u];
		if(!rk){
			rk=k;
			for(int i=0; i<p[u].size(); ++i)
				rk=min(rk, rankk[p[u][i]]-1);
		}
		rankk[u]=rk;
		is[rk]=1;
		ls=min(ls,rk);
		for(int i=0; i<g[u].size(); ++i){
			if(rankk[g[u][i]]>rk)
				no();
			if(!--indeg[g[u][i]])
				q.push(g[u][i]);
		}
	}
	if(cttt<n || ls<1)
		no();
	set<int> st;
	set<ii> oth;
	for(int i=1; i<=k; ++i)
		if(!is[i])
			st.insert(i);
	priority_queue<ii> qq;
	for(int i=0; i<n; ++i){
		++fr[rankk[i]];
		if(!rdeg[i])
			qq.push(ii(-rankk[i],i));
	}
	while(!qq.empty()&&!st.empty()){
		int u=qq.top().second;
		qq.pop();
		bool fff=1;
		int d=*st.begin();
		if(!al[u] && rankk[u]>d){
			st.erase(st.begin());
			if(!--fr[rankk[u]])
				st.insert(rankk[u]);
			++fr[d];
			rankk[u]=d;
		}else if(al[u] && rankk[u]>d)
			oth.insert(ii(rankk[u],u)),fff=0;
		if(fff)
		for(int i=0; i<p[u].size(); ++i)
			if(!--rdeg[p[u][i]])
				qq.push(ii(-rankk[p[u][i]],p[u][i]));
		while(!oth.empty() && !st.empty() && oth.begin()->first<*st.begin()){
			qq.push(ii(-rankk[oth.begin()->first], oth.begin()->second));
			oth.erase(oth.begin());
		}
	}
	if(st.size())
		no();
	for(int i=0; i<n; ++i)
		printf("%d ", rankk[i]);
	puts("");
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ii pair<int,int>
const int N=200001;
const int oo=1000000000;
int n,m,k,indeg[N],rank[N],ans[N],is[N];
vector<int> g[N], p[N];
void no(){
	cout<<-1<<endl;
	exit(0);
}
int main(){
	cin>>n>>m>>k;
	if(k>n)
		no();
	for(int i=0; i<n; ++i)
		scanf("%d",&rank[i]);
	for(int a,b,i=0; i<m; ++i){
		scanf("%d%d",&a,&b);
		--a;--b;
		++indeg[b];
		g[a].pb(b);
		p[b].pb(a);
	}
	queue<int> q;
	for(int i=0; i<n; ++i)
		if(!indeg[i])
			q.push(i);
	vector<ii> v;
	int ls=k;
	while(!q.empty()){
		int u=q.front();
		q.pop();
		int rk=rank[u];
		if(!rk){
			rk=k;
			for(int i=0; i<p[u].size(); ++i)
				rk=min(rk, rank[p[u][i]]-1);
		}
		rank[u]=rk;
		//cout<<u+1<<" "<<rk<<endl;
		is[rk]=1;
		ls=min(ls,rk);
		v.pb(ii(rk,u));
		for(int i=0; i<g[u].size(); ++i){
			if(rank[g[u][i]]>rk)
				no();
			if(!--indeg[g[u][i]])
				q.push(g[u][i]);
		}
	}
	if(v.size()<n || ls<1)
		no();
	priority_queue<int> pq;
	set<int> till;
	for(int i=1; i<=k; ++i)
		if(!is[i])
			pq.push(i);
	sort(v.rbegin(), v.rend());
	for(int i=0; i<v.size(); ++i){
		//cout<<v[i].first<<" "<<v[i].second<<endl;
		while(!till.empty() && v[i].first<*till.begin())
			till.erase(till.begin());
		v[i].first-=till.size();
		if(i&&v[i].first==v[i-1].first && pq.size()){
			int d=pq.top();
			if(d>v[i].first)
				no();
			pq.pop();
			till.insert(d);
			--v[i].first;
		}
		ans[v[i].second]=v[i].first;
	}
	memset(is,0,sizeof(is));
	for(int i=0; i<n; ++i)
		is[ans[i]]=1;
	for(int i=1; i<=k; ++i)
		if(!is[i])
			no();
	for(int i=0; i<n; ++i)
		printf("%d ", ans[i]);
	puts("");
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ii pair<int,int>
const int N=200001;
const int oo=1000000000;
int n,m,k,indeg[N],rdeg[N],fr[N],rankk[N],ans[N],is[N],al[N];
vector<int> g[N], p[N];
void no(){
	cout<<-1<<endl;
	exit(0);
}
int main(){
	cin>>n>>m>>k;
	if(k>n)
		no();
	for(int i=0; i<n; ++i){
		scanf("%d",&rankk[i]);
		if(rankk[i])
			al[i]=1;
	}
	for(int a,b,i=0; i<m; ++i){
		scanf("%d%d",&a,&b);
		--a;--b;
		++indeg[b];
		++rdeg[a];
		g[a].pb(b);
		p[b].pb(a);
	}
	queue<int> q;
	for(int i=0; i<n; ++i)
		if(!indeg[i])
			q.push(i);
	int ls=k,cttt=0;
	while(!q.empty()){
		int u=q.front();
		q.pop();
		++cttt;
		int rk=rankk[u];
		if(!rk){
			rk=k;
			for(int i=0; i<p[u].size(); ++i)
				rk=min(rk, rankk[p[u][i]]-1);
		}
		rankk[u]=rk;
		is[rk]=1;
		ls=min(ls,rk);
		for(int i=0; i<g[u].size(); ++i){
			if(rankk[g[u][i]]>=rk)
				no();
			if(!--indeg[g[u][i]])
				q.push(g[u][i]);
		}
	}
	if(cttt<n || ls<1)
		no();
	set<int> st;
	set<ii> oth;
	for(int i=1; i<=k; ++i)
		if(!is[i])
			st.insert(i);
	priority_queue<ii> qq;
	for(int i=0; i<n; ++i){
		++fr[rankk[i]];
		if(!rdeg[i])
			qq.push(ii(-rankk[i],i));
	}
	while(!qq.empty()&&!st.empty()){
		int u=qq.top().second;
		qq.pop();
		bool fff=1;
		int d=*st.begin();
		if(!al[u] && rankk[u]>d){
			st.erase(st.begin());
			if(!--fr[rankk[u]])
				st.insert(rankk[u]);
			++fr[d];
			rankk[u]=d;
		}else if(al[u] && rankk[u]>d)
			oth.insert(ii(rankk[u],u)),fff=0;
		if(fff)
		for(int i=0; i<p[u].size(); ++i)
			if(!--rdeg[p[u][i]])
				qq.push(ii(-rankk[p[u][i]],p[u][i]));
		while(!oth.empty() && !st.empty() && oth.begin()->first<*st.begin()){
			qq.push(ii(-oth.begin()->first, oth.begin()->second));
			oth.erase(oth.begin());
		}
	}
	if(st.size())
		no();
	for(int i=0; i<n; ++i)
		printf("%d ", rankk[i]);
	puts("");
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ii pair<int,int>
const int N=200001;
const int oo=1000000000;
int n,m,k,indeg[N],rdeg[N],fr[N],rankk[N],ans[N],is[N],al[N];
vector<int> g[N], p[N];
void no(){
	cout<<-1<<endl;
	exit(0);
}
int main(){
	cin>>n>>m>>k;
	if(k>n)
		no();
	for(int i=0; i<n; ++i){
		scanf("%d",&rankk[i]);
		if(rankk[i])
			al[i]=1;
	}
	for(int a,b,i=0; i<m; ++i){
		scanf("%d%d",&a,&b);
		--a;--b;
		++indeg[b];
		++rdeg[a];
		g[a].pb(b);
		p[b].pb(a);
	}
	queue<int> q;
	for(int i=0; i<n; ++i)
		if(!indeg[i])
			q.push(i);
	int ls=k,cttt=0;
	while(!q.empty()){
		int u=q.front();
		q.pop();
		++cttt;
		int rk=rankk[u];
		if(!rk){
			rk=k;
			for(int i=0; i<p[u].size(); ++i)
				rk=min(rk, rankk[p[u][i]]-1);
		}
		rankk[u]=rk;
		is[rk]=1;
		ls=min(ls,rk);
		for(int i=0; i<g[u].size(); ++i){
			if(rankk[g[u][i]]>rk)
				no();
			if(!--indeg[g[u][i]])
				q.push(g[u][i]);
		}
	}
	if(cttt<n || ls<1)
		no();
	set<int> st;
	for(int i=1; i<=k; ++i)
		if(!is[i])
			st.insert(i);
	priority_queue<ii> qq;
	for(int i=0; i<n; ++i){
		++fr[rankk[i]];
		if(!rdeg[i])
			qq.push(ii(-rankk[i],i));
	}
	while(!qq.empty()&&!st.empty()){
		int u=qq.top().second;
		qq.pop();
		if(al[u])continue;
		int d=*st.begin();
		st.erase(st.begin());
		if(!--fr[rankk[u]])
			st.insert(rankk[u]);
		++fr[d];
		rankk[u]=d;
		for(int i=0; i<p[u].size(); ++i)
			if(!--rdeg[p[u][i]])
				qq.push(ii(-rankk[p[u][i]],p[u][i]));
	}
	if(st.size())
		no();
	for(int i=0; i<n; ++i)
		printf("%d ", rankk[i]);
	puts("");
}