#include<functional>
#include<algorithm>
#include<string.h>
#include<stdio.h>
#include<cmath>
using namespace std;
#define clr(a) memset(a,0,sizeof(a))
//--Container
#include<queue>
#include<set>
//
typedef long long ll;
const int up=200000;

struct eg{int u,v,nx;}gp[(up<<1)+10];int cnt,hd[(up<<1)+10],dl[up+10],dr[up+10],n,m,dk,bd[up+10],wg[up+10],in[up+10],ou[up+10],tmp[up+10];
inline void psh(int u,int v){++cnt;gp[cnt].v=v,gp[cnt].u=u,gp[cnt].nx=hd[u],hd[u]=cnt;};
struct ti{int a;ti(int A=0):a(A){};
friend bool operator<(const ti&,const ti&);friend bool operator>(const ti&,const ti&);friend bool operator==(const ti&,const ti&);
};
bool operator<(const ti&a,const ti&b){return dr[a.a]==dr[b.a]?dl[a.a]<dl[b.a]:dr[a.a]<dr[b.a];};
bool operator>(const ti&a,const ti&b){return dr[a.a]==dr[b.a]?dl[a.a]>dl[b.a]:dr[a.a]>dr[b.a];};
bool operator==(const ti&a,const ti&b){return dl[a.a]==dl[b.a]&&dr[a.a]==dr[b.a];};

bool dfq(){
    int i,j;for(i=1;i<=n;++i)tmp[i]=ou[i];queue<int>qe;for(clr(bd),i=1;i<=n;++i)if(!tmp[i])qe.push(i);
    for(;!qe.empty();){
        int v=qe.front();qe.pop();bd[v]=1;for(i=hd[v+n];i;i=gp[i].nx){
            --tmp[gp[i].v];if(!tmp[gp[i].v])qe.push(gp[i].v);
        }
    }
    for(i=1;i<=n;++i)if(!bd[i])return 0;
    return 1;
};
bool dfx(int v){
    int i,j;bd[v]=1;for(dl[v]=0,i=hd[v];i;i=gp[i].nx){
        if(!bd[gp[i].v]&&!dfx(gp[i].v))return 0;
        dl[v]=max(dl[v],dl[gp[i].v]);
    }
    dl[v]++;
    if(dl[v]>dk)return 0;
    if(wg[v]&&wg[v]<dl[v])return 0;
    if(wg[v])dl[v]=wg[v];
    return 1;
};
bool dfz(){
    int i,j;queue<int>qe;for(clr(bd),i=1;i<=n;++i)if(!in[i])qe.push(i),dr[i]=wg[i]?wg[i]:dk;
    for(;!qe.empty();){
        int v=qe.front();qe.pop();if(dr[i]<dl[i])return 0;
        for(i=hd[v];i;i=gp[i].nx){
            if(!bd[gp[i].v]){dr[gp[i].v]=up+233;}
            --in[gp[i].v],dr[gp[i].v]=min(dr[gp[i].v],dr[v]-1);
            if(!in[gp[i].v]){
                if(wg[gp[i].v]&&wg[gp[i].v]>dr[gp[i].v])return 0;
                if(wg[gp[i].v])dr[gp[i].v]=wg[gp[i].v];
                bd[gp[i].v]=1,qe.push(gp[i].v);
            }
        }
    }
    return 1;
};

void _cl(){
    int i,j,rs,d,k;priority_queue<ti,vector<ti>,greater<ti> >qe;for(i=1;i<=n;++i)if(!ou[i])qe.push(ti(i));
    set<int>st;for(i=1;i<=dk;st.insert(i++));
    for(rs=1;!qe.empty();){
        int v=qe.top().a;qe.pop();set<int>::iterator zt=st.lower_bound(dl[v]);
        if(zt==st.end()||*zt>dr[v])dl[v]=dr[v];
        else
            dl[v]=*zt,st.erase(zt);
        for(i=hd[v+n];i;i=gp[i].nx){
            dl[gp[i].v]=max(dl[gp[i].v],dl[v]+1);
            --ou[gp[i].v];if(!ou[gp[i].v])qe.push(gp[i].v);
        }
    }
    if(!st.empty())printf("-1\n");
    else{
        for(printf("%d",dl[1]),i=2;i<=n;printf(" %d",dl[i++]));putchar('\n');
    }
};

void cl(){
    int i,j,k,a,b;bool fg=1;scanf("%d %d %d",&n,&m,&dk);
    for(cnt=0,clr(hd),i=1;i<=n;scanf("%d",&wg[i++]));
    for(i=0;i<m;++i){scanf("%d %d",&a,&b);psh(a,b);psh(b+n,a);++in[b],++ou[a];}
    if(!dfq()){printf("-1\n");return;}
    for(clr(bd),i=1;i<=n;++i)if(!in[i]&&!dfx(i))fg=0;
    if(!fg||!dfz()){printf("-1\n");return;}
    _cl();
};

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif
    cl();
	return 0;
};


/*
 * test.cpp
 *
 *
 *      Author: Fireworks
 */

#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
#include<map>
#include<cmath>
#include<bitset>
#include<set>
#include<iomanip>
#include<fstream>
#include<bitset>
#include<cstring>
#include<cstdlib>
#include<complex>
#include<list>
#include<sstream>
#include<cassert>   // assert

using namespace std;

#define double long double

typedef pair<int,int> ii;
typedef pair<int,long long> il;
typedef pair<long long,long long> ll;
typedef pair<ll,int> lli;
typedef pair<long long,int> li;
typedef pair<double,double> dd;
typedef pair<ii,int> iii;
typedef pair<double,int> di;
long long mod = 1000000007LL;
long long base = 10000007;
long long large = 1000000000000000000LL;

vector<int> dfs_num,dfs_low,S,visited;
vector<vector<int> > adj;
vector<vector<int> > Scc;
int dfsNumberCounter = 0, numSCC = 0;
void tarjanSCC(int u){
	dfs_low[u]=dfs_num[u]=dfsNumberCounter++;
	S.push_back(u);
	visited[u]=1;
	for(int j=0;j<(int)adj[u].size();j++){
		int v = adj[u][j];
		if(dfs_num[v]==-1){
			tarjanSCC(v);
		}
		if(visited[v]==1){
			dfs_low[u]=min(dfs_low[u],dfs_low[v]);
		}
	}

	if(dfs_low[u]==dfs_num[u]){
		Scc.push_back(vector<int>(0,0));
		while(true){
			int v= S.back();
			S.pop_back();
			visited[v]=0;
			Scc[numSCC].push_back(v);
			if(u==v) break;
		}
		numSCC++;
	}
}

int main(){
	int n,m,k;
	cin>>n>>m>>k;
	k--;
	dfs_num.assign(n,-1);
	dfs_low.assign(n,0);
	visited.assign(n,0);
	adj.assign(n,vector<int>(0,0));
	vector<int> a(n,0);
	for(int i=0;i<n;i++){
		cin>>a[i];
		a[i]--;
	}

	for(int i=0;i<m;i++){
		int x,y;
		cin>>x>>y;
		x--;y--;
		adj[x].push_back(y);
	}

	for(int i=0;i<n;i++){
		if(dfs_num[i]==-1){
			tarjanSCC(i);
		}
	}

	bool flag = true;
	for(int i=0;i<numSCC;i++){
		if(Scc[i].size()>1) flag = false;
	}
	if(!flag){
		cout<<-1<<endl;
		return 0;
	}

	vector<vector<int> > in(n,vector<int>(0,0));
	for(int i=0;i<n;i++){
		for(int j=0;j<(int)adj[i].size();j++){
			int v = adj[i][j];
			in[v].push_back(i);
		}
	}
	vector<int> deg(n,0);
	for(int i=0;i<n;i++) deg[i] = (int)in[i].size();
	set<int> s;
	for(int i=0;i<n;i++) if(deg[i]==0) {
		s.insert(i);
	}
	while(!s.empty()){
		int u = *s.begin();
		s.erase(u);

		if(a[u]!=-1){
			for(int j=0;j<(int)in[u].size();j++){
				int from = in[u][j];
				if(a[u]>=a[from]) flag = false;
			}
			if(!flag) break;
		}else{
			a[u] = k;
			for(int j=0;j<(int)in[u].size();j++){
				int from = in[u][j];
				a[u] = min(a[u],a[from]-1);
			}
		}
		for(int j=0;j<(int)adj[u].size();j++){
			int v = adj[u][j];
			deg[v]--;
			if(deg[v]==0) s.insert(v);
		}
	}

	for(int i=0;i<n;i++) if(a[i]<0) flag = false;
	if(!flag){
		cout<<"-1"<<endl;
		return 0;
	}

	for(int i=0;i<n;i++) cout<<a[i]+1<<" ";
	cout<<endl;

    return 0;

}


#include <bits/stdc++.h>

using namespace std;

#define double long double

typedef pair<int,int> ii;
typedef pair<int,long long> il;
typedef pair<long long,long long> ll;
typedef pair<ll,int> lli;
typedef pair<long long,int> li;
typedef pair<double,double> dd;
typedef pair<ii,int> iii;
typedef pair<double,int> di;
typedef pair<int,ii> iii2;
typedef pair<ii,ii> iiii;
long long mod = 1000000007LL;
long long large = 1000000000000000000LL;

vector<int> dfs_num,dfs_low,S,visited;
vector<vector<int> > adj;
vector<vector<int> > Scc;
int dfsNumberCounter = 0, numSCC = 0;
void tarjanSCC(int u){
	dfs_low[u]=dfs_num[u]=dfsNumberCounter++;
	S.push_back(u);
	visited[u]=1;
	for(int j=0;j<(int)adj[u].size();j++){
		int v = adj[u][j];
		if(dfs_num[v]==-1){
			tarjanSCC(v);
		}
		if(visited[v]==1){
			dfs_low[u]=min(dfs_low[u],dfs_low[v]);
		}
	}

	if(dfs_low[u]==dfs_num[u]){
		Scc.push_back(vector<int>(0,0));
		while(true){
			int v= S.back();
			S.pop_back();
			visited[v]=0;
			Scc[numSCC].push_back(v);
			if(u==v) break;
		}
		numSCC++;
	}
}

int uv,up;
vector<int> mini;
void update(int o,int l,int r){
	if(l==r){
		mini[o] = uv;
	}else{
		int m = (l+r)/2;
		if(up<=m) update(o*2,l,m);
		if(up>m) update(o*2+1,m+1,r);
		mini[o] = min(mini[o*2],mini[o*2+1]);
	}
}

int ql,qr,re;

void query(int o,int l,int r){
	if(ql<=l&&qr>=r){
		re = min(re,mini[o]);
	}else{
		int m = (l+r)/2;
		if(ql<=m) query(o*2,l,m);
		if(qr>m) query(o*2+1,m+1,r);
	}
}

int main(){
	int n,m,k;
	cin>>n>>m>>k;
	k--;
	dfs_num.assign(n,-1);
	dfs_low.assign(n,0);
	visited.assign(n,0);
	adj.assign(n,vector<int>(0,0));
	vector<int> a(n,0);
	for(int i=0;i<n;i++){
		cin>>a[i];
		a[i]--;
	}
	vector<int> b = a;

	for(int i=0;i<m;i++){
		int x,y;
		cin>>x>>y;
		x--;y--;
		adj[x].push_back(y);
	}

	for(int i=0;i<n;i++){
		if(dfs_num[i]==-1){
			tarjanSCC(i);
		}
	}

	bool flag = true;
	for(int i=0;i<numSCC;i++){
		if(Scc[i].size()>1) flag = false;
	}
	if(!flag){
		cout<<-1<<endl;
		return 0;
	}

	vector<vector<int> > in(n,vector<int>(0,0));
	for(int i=0;i<n;i++){
		for(int j=0;j<(int)adj[i].size();j++){
			int v = adj[i][j];
			in[v].push_back(i);
		}
	}
	vector<int> deg(n,0);
	for(int i=0;i<n;i++) deg[i] = (int)in[i].size();
	set<int> s;
	for(int i=0;i<n;i++) if(deg[i]==0) {
		s.insert(i);
	}
	while(!s.empty()){
		int u = *s.begin();
		s.erase(u);

		if(a[u]!=-1){
			for(int j=0;j<(int)in[u].size();j++){
				int from = in[u][j];
				if(a[u]>=a[from]) flag = false;
			}
			if(!flag) break;
		}else{
			a[u] = k;
			for(int j=0;j<(int)in[u].size();j++){
				int from = in[u][j];
				a[u] = min(a[u],a[from]-1);
			}
		}
		for(int j=0;j<(int)adj[u].size();j++){
			int v = adj[u][j];
			deg[v]--;
			if(deg[v]==0) s.insert(v);
		}
	}

	for(int i=0;i<n;i++) if(a[i]<0) flag = false;
	if(!flag){
		cout<<"-1"<<endl;
		return 0;
	}

	mini.assign(4*k+10,0);

	vector<int> cnt(k+1,0);
	for(int i=0;i<n;i++) cnt[a[i]]++;
	for(int i=0;i<=k;i++){
		up = i;
		uv = i;
		if(cnt[i]!=0) uv = 1000000;
		update(1,0,k);
	}

	vector<ii> e;
	for(int i=0;i<n;i++) e.push_back(ii(a[i],i));
	sort(e.begin(),e.end());
	for(int i=0;i<n;i++){
		int t = e[i].second;
		if(b[t]!=-1) continue;
		ql = 0;
		for(int j=0;j<(int)adj[t].size();j++){
			int v = adj[t][j];
			ql = max(ql,a[v]+1);
		}
		qr = a[t]-1;
		if(qr<ql) continue;
		re = 1000000;
		query(1,0,k);
		if(re==1000000) continue;
		cnt[a[t]]--;
		if(cnt[a[t]]==0){
			up = a[t];
			uv = a[t];
			update(1,0,k);
		}
		a[t] =re;
		cnt[re]++;
		up = re;
		uv = 1000000;
		update(1,0,k);
	}

	if(mini[1]!=1000000){
		cout<<"-1"<<endl;
		return 0;
	}

	for(int i=0;i<n;i++) cout<<a[i]+1<<" ";
	cout<<endl;

    return 0;

}


#include <bits/stdc++.h>

using namespace std;

#define double long double

typedef pair<int,int> ii;
typedef pair<int,long long> il;
typedef pair<long long,long long> ll;
typedef pair<ll,int> lli;
typedef pair<long long,int> li;
typedef pair<double,double> dd;
typedef pair<ii,int> iii;
typedef pair<double,int> di;
typedef pair<int,ii> iii2;
typedef pair<ii,ii> iiii;
long long mod = 1000000007LL;
long long large = 1000000000000000000LL;

vector<int> dfs_num,dfs_low,S,visited;
vector<vector<int> > adj;
vector<vector<int> > Scc;
int dfsNumberCounter = 0, numSCC = 0;
void tarjanSCC(int u){
	dfs_low[u]=dfs_num[u]=dfsNumberCounter++;
	S.push_back(u);
	visited[u]=1;
	for(int j=0;j<(int)adj[u].size();j++){
		int v = adj[u][j];
		if(dfs_num[v]==-1){
			tarjanSCC(v);
		}
		if(visited[v]==1){
			dfs_low[u]=min(dfs_low[u],dfs_low[v]);
		}
	}

	if(dfs_low[u]==dfs_num[u]){
		Scc.push_back(vector<int>(0,0));
		while(true){
			int v= S.back();
			S.pop_back();
			visited[v]=0;
			Scc[numSCC].push_back(v);
			if(u==v) break;
		}
		numSCC++;
	}
}

int uv,up;
vector<int> mini;
void update(int o,int l,int r){
	if(l==r){
		mini[o] = uv;
	}else{
		int m = (l+r)/2;
		if(up<=m) update(o*2,l,m);
		if(up>m) update(o*2+1,m+1,r);
		mini[o] = min(mini[o*2],mini[o*2+1]);
	}
}

int ql,qr,re;

void query(int o,int l,int r){
	if(ql<=l&&qr>=r){
		re = min(re,mini[o]);
	}else{
		int m = (l+r)/2;
		if(ql<=m) query(o*2,l,m);
		if(qr>m) query(o*2+1,m+1,r);
	}
}

int main(){
	int n,m,k;
	cin>>n>>m>>k;
	k--;
	dfs_num.assign(n,-1);
	dfs_low.assign(n,0);
	visited.assign(n,0);
	adj.assign(n,vector<int>(0,0));
	vector<int> a(n,0);
	for(int i=0;i<n;i++){
		cin>>a[i];
		a[i]--;
	}
	vector<int> b = a;

	for(int i=0;i<m;i++){
		int x,y;
		cin>>x>>y;
		x--;y--;
		adj[x].push_back(y);
	}

	for(int i=0;i<n;i++){
		if(dfs_num[i]==-1){
			tarjanSCC(i);
		}
	}

	bool flag = true;
	for(int i=0;i<numSCC;i++){
		if(Scc[i].size()>1) flag = false;
	}
	if(!flag){
		cout<<-1<<endl;
		return 0;
	}

	vector<vector<int> > in(n,vector<int>(0,0));
	for(int i=0;i<n;i++){
		for(int j=0;j<(int)adj[i].size();j++){
			int v = adj[i][j];
			in[v].push_back(i);
		}
	}
	vector<int> deg(n,0);
	for(int i=0;i<n;i++) deg[i] = (int)in[i].size();
	set<int> s;
	for(int i=0;i<n;i++) if(deg[i]==0) {
		s.insert(i);
	}
	while(!s.empty()){
		int u = *s.begin();
		s.erase(u);

		if(a[u]!=-1){
			for(int j=0;j<(int)in[u].size();j++){
				int from = in[u][j];
				if(a[u]>=a[from]) flag = false;
			}
			if(!flag) break;
		}else{
			a[u] = k;
			for(int j=0;j<(int)in[u].size();j++){
				int from = in[u][j];
				a[u] = min(a[u],a[from]-1);
			}
		}
		for(int j=0;j<(int)adj[u].size();j++){
			int v = adj[u][j];
			deg[v]--;
			if(deg[v]==0) s.insert(v);
		}
	}

	for(int i=0;i<n;i++) if(a[i]<0) flag = false;
	if(!flag){
		cout<<"-1"<<endl;
		return 0;
	}

	mini.assign(4*k+10,0);

	vector<int> cnt(k,0);
	for(int i=0;i<n;i++) cnt[a[i]]++;
	for(int i=0;i<k;i++){
		up = i;
		uv = i;
		if(cnt[i]!=0) uv = 1000000;
		update(1,0,k-1);
	}

	vector<ii> e;
	for(int i=0;i<n;i++) e.push_back(ii(a[i],i));
	sort(e.begin(),e.end());
	for(int i=0;i<n;i++){
		int t = e[i].second;
		if(b[t]!=-1) continue;
		ql = 0;
		for(int j=0;j<(int)adj[t].size();j++){
			int v = adj[t][j];
			ql = max(ql,a[v]+1);
		}
		qr = a[t]-1;
		if(qr<ql) continue;
		re = 1000000;
		query(1,0,k-1);
		if(re==1000000) continue;
		cnt[a[t]]--;
		if(cnt[a[t]]==0){
			up = a[t];
			uv = a[t];
			update(1,0,k-1);
		}
		a[t] =re;
		cnt[re]++;
		up = re;
		uv = 1000000;
		update(1,0,k-1);
	}

	if(mini[1]!=1000000){
		cout<<"-1"<<endl;
		return 0;
	}

	for(int i=0;i<n;i++) cout<<a[i]+1<<" ";
	cout<<endl;

    return 0;

}


#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <sstream>
#include <queue>
#include <algorithm>
using namespace std;

typedef pair <int, int> ii;

const int Maxn = 200005;

int n, m, k;
int r[Maxn];
vector <int> neigh[Maxn], rneigh[Maxn];
int in[Maxn], out[Maxn];
set <int> S;
int mn[Maxn], mx[Maxn];
vector <int> add[Maxn];

int main()
{
	scanf("%d %d %d", &n, &m, &k);
	for (int i = 1; i <= k; i++)
		S.insert(i);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &r[i]);
		if (r[i] > 0) { S.erase(r[i]); mn[i] = r[i]; mx[i] = r[i]; }
		else mn[i] = 1, mx[i] = k;
	}
	for (int i = 0; i < m; i++) {
		int a, b; scanf("%d %d", &a, &b);
		neigh[a].push_back(b);
		rneigh[b].push_back(a);
		out[a]++; in[b]++;
	}
	vector <int> seq;
	for (int i = 1; i <= n; i++)
		if (out[i] == 0) seq.push_back(i);
	for (int i = 0; i < seq.size(); i++) {
		int v = seq[i];
		if (r[v] > 0 && mn[v] > r[v]) { printf("-1\n"); return 0; }
		for (int j = 0; j < rneigh[v].size(); j++) {
			int u = rneigh[v][j];
			mn[u] = max(mn[u], mn[v] + 1);
			if (--out[u] == 0) seq.push_back(u);
		}
	}
	if (seq.size() < n) { printf("-1\n"); return 0; }
	seq.clear();
	for (int i = 1; i <= n; i++)
		if (in[i] == 0) seq.push_back(i);
	for (int i = 0; i < seq.size(); i++) {
		int v = seq[i];
		if (r[v] > 0 && mx[v] < r[v]) { printf("-1\n"); return 0; }
		for (int j = 0; j < neigh[v].size(); j++) {
			int u = neigh[v][j];
			mx[u] = min(mx[u], mx[v] - 1);
			if (--in[u] == 0) seq.push_back(u);
		}
	}
	if (seq.size() < n) { printf("-1\n"); return 0; }
	for (int i = 1; i <= n; i++)
		add[mx[i]].push_back(i);
	priority_queue <ii> Q;
	for (int i = k; i > 0; i--) {
		for (int j = 0; j < add[i].size(); j++) {
			int ind = add[i][j];
			Q.push(ii(mn[ind], ind));
		}
		if (S.find(i) != S.end()) {
			while (!Q.empty() && Q.top().first > i) {
				ii v = Q.top(); Q.pop();
				r[v.second] = v.first;
			}
			if (Q.empty()) { printf("-1\n"); return 0; }
			ii v = Q.top(); Q.pop();
			r[v.second] = i;
		}
	}
	while (!Q.empty()) {
		ii v = Q.top(); Q.pop();
		r[v.second] = v.first;
	}
	for (int i = 1; i <= n; i++)
		printf("%d%c", r[i], i + 1 <= n? ' ': '\n');
	return 0;
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <sstream>
#include <queue>
#include <algorithm>
using namespace std;

typedef pair <int, int> ii;

const int Maxn = 200005;

int n, m, k;
int r[Maxn];
vector <int> neigh[Maxn], rneigh[Maxn];
int in[Maxn], out[Maxn];
set <int> S;
int mn[Maxn], mx[Maxn];
vector <int> add[Maxn];

int main()
{
	scanf("%d %d %d", &n, &m, &k);
	for (int i = 1; i <= k; i++)
		S.insert(i);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &r[i]);
		if (r[i] > 0) { S.erase(r[i]); mn[i] = r[i]; mx[i] = r[i]; }
		else mn[i] = 1, mx[i] = k;
	}
	for (int i = 0; i < m; i++) {
		int a, b; scanf("%d %d", &a, &b);
		neigh[a].push_back(b);
		rneigh[b].push_back(a);
		out[a]++; in[b]++;
	}
	vector <int> seq;
	for (int i = 1; i <= n; i++)
		if (out[i] == 0) seq.push_back(i);
	for (int i = 0; i < seq.size(); i++) {
		int v = seq[i];
		if (r[v] > 0 && mn[v] > r[v]) { printf("-1\n"); return 0; }
		for (int j = 0; j < rneigh[v].size(); j++) {
			int u = rneigh[v][j];
			mn[u] = max(mn[u], mn[v] + 1);
			if (--out[u] == 0) seq.push_back(u);
		}
	}
	if (seq.size() < n) { printf("-1\n"); return 0; }
	seq.clear();
	for (int i = 1; i <= n; i++)
		if (in[i] == 0) seq.push_back(i);
	for (int i = 0; i < seq.size(); i++) {
		int v = seq[i];
		if (r[v] > 0 && mx[v] < r[v]) { printf("-1\n"); return 0; }
		if (mx[v] < mn[v]) { printf("-1\n"); return 0; }
		for (int j = 0; j < neigh[v].size(); j++) {
			int u = neigh[v][j];
			mx[u] = min(mx[u], mx[v] - 1);
			if (--in[u] == 0) seq.push_back(u);
		}
	}
	if (seq.size() < n) { printf("-1\n"); return 0; }
	for (int i = 1; i <= n; i++)
		add[mx[i]].push_back(i);
	priority_queue <ii> Q;
	for (int i = k; i > 0; i--) {
		for (int j = 0; j < add[i].size(); j++) {
			int ind = add[i][j];
			Q.push(ii(mn[ind], ind));
		}
		if (S.find(i) != S.end()) {
			while (!Q.empty() && Q.top().first > i) {
				ii v = Q.top(); Q.pop();
				r[v.second] = v.first;
			}
			if (Q.empty()) { printf("-1\n"); return 0; }
			ii v = Q.top(); Q.pop();
			r[v.second] = i;
		}
	}
	while (!Q.empty()) {
		ii v = Q.top(); Q.pop();
		r[v.second] = v.first;
	}
	for (int i = 1; i <= n; i++)
		printf("%d%c", r[i], i + 1 <= n? ' ': '\n');
	return 0;
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <sstream>
#include <queue>
#include <algorithm>
using namespace std;

typedef pair <int, int> ii;

const int Maxn = 200005;

int n, m, k;
int r[Maxn];
vector <int> neigh[Maxn], rneigh[Maxn];
int in[Maxn], out[Maxn];
set <int> S;
int mn[Maxn], mx[Maxn];

bool Less(const int &a, const int &b)
{
	if (mn[a] != mn[b]) return mn[a] > mn[b];
	if (mx[a] != mx[b]) return mx[a] > mx[b];
	return a < b;
}

int main()
{
	scanf("%d %d %d", &n, &m, &k);
	for (int i = 1; i <= k; i++)
		S.insert(i);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &r[i]);
		if (r[i] > 0) { S.erase(r[i]); mn[i] = r[i]; mx[i] = r[i]; }
		else mn[i] = 1, mx[i] = k;
	}
	for (int i = 0; i < m; i++) {
		int a, b; scanf("%d %d", &a, &b);
		neigh[a].push_back(b);
		rneigh[b].push_back(a);
		out[a]++; in[b]++;
	}
	vector <int> seq;
	for (int i = 1; i <= n; i++)
		if (out[i] == 0) seq.push_back(i);
	for (int i = 0; i < seq.size(); i++) {
		int v = seq[i];
		if (r[v] > 0 && mn[v] > r[v]) { printf("-1\n"); return 0; }
		for (int j = 0; j < rneigh[v].size(); j++) {
			int u = rneigh[v][j];
			mn[u] = max(mn[u], mn[v] + 1);
			if (--out[u] == 0) seq.push_back(u);
		}
	}
	if (seq.size() < n) { printf("-1\n"); return 0; }
	seq.clear();
	for (int i = 1; i <= n; i++)
		if (in[i] == 0) seq.push_back(i);
	for (int i = 0; i < seq.size(); i++) {
		int v = seq[i];
		if (r[v] > 0 && mx[v] < r[v]) { printf("-1\n"); return 0; }
		for (int j = 0; j < neigh[v].size(); j++) {
			int u = neigh[v][j];
			mx[u] = min(mx[u], mx[v] - 1);
			if (--in[u] == 0) seq.push_back(u);
		}
	}
	if (seq.size() < n) { printf("-1\n"); return 0; }
	sort(seq.begin(), seq.end(), Less);
	for (int i = 0; i < seq.size(); i++) {
		int v = seq[i];
		bool was = r[v] > 0;
		if (!was) {
			set <int>::iterator it = S.upper_bound(mx[v]);
			if (it != S.begin()) {
				it--;
				if (mn[v] <= *it) { was = true; r[v] = *it; S.erase(*it); }
			}
			if (!was) r[v] = mn[v];
		}
	}
	if (!S.empty()) { printf("-1\n"); return 0; }
	for (int i = 1; i <= n; i++)
		printf("%d%c", r[i], i + 1 <= n? ' ': '\n');
	return 0;
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
using namespace std;

const int Maxn = 200005;

int n, m, k;
int r[Maxn];
vector <int> neigh[Maxn], rneigh[Maxn];
int in[Maxn], out[Maxn];
set <int> S;
int mn[Maxn], mx[Maxn];

int main()
{
	scanf("%d %d %d", &n, &m, &k);
	for (int i = 1; i <= k; i++)
		S.insert(i);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &r[i]);
		if (r[i] > 0) { S.erase(r[i]); mn[i] = r[i]; mx[i] = r[i]; }
		else mn[i] = 1, mx[i] = k;
	}
	for (int i = 0; i < m; i++) {
		int a, b; scanf("%d %d", &a, &b);
		neigh[a].push_back(b);
		rneigh[b].push_back(a);
		out[a]++; in[b]++;
	}
	vector <int> seq;
	for (int i = 1; i <= n; i++)
		if (out[i] == 0) seq.push_back(i);
	for (int i = 0; i < seq.size(); i++) {
		int v = seq[i];
		if (r[v] > 0 && mn[v] > r[v]) { printf("-1\n"); return 0; }
		for (int j = 0; j < rneigh[v].size(); j++) {
			int u = rneigh[v][j];
			mn[u] = max(mn[u], mn[v] + 1);
			if (--out[u] == 0) seq.push_back(u);
		}
	}
	if (seq.size() < n) { printf("-1\n"); return 0; }
	seq.clear();
	for (int i = 1; i <= n; i++)
		if (in[i] == 0) seq.push_back(i);
	for (int i = 0; i < seq.size(); i++) {
		int v = seq[i];
		bool was = r[v] > 0;
		if (!was) {
			set <int>::iterator it = S.upper_bound(mx[v]);
			if (it != S.begin()) {
				it--;
				if (mn[v] <= *it) { was = true; r[v] = mx[v] = *it;  S.erase(it); }
			}
			if (!was) r[v] = mx[v];
		}
		for (int j = 0; j < neigh[v].size(); j++) {
			int u = neigh[v][j];
			mx[u] = min(mx[u], mx[v] - 1);
			if (--in[u] == 0) seq.push_back(u);
		}
	}
	if (!S.empty()) { printf("-1\n"); return 0; }
	for (int i = 1; i <= n; i++)
		printf("%d%c", r[i], i + 1 <= n? ' ': '\n');
	return 0;
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <sstream>
#include <queue>
#include <algorithm>
using namespace std;

typedef pair <int, int> ii;

const int Maxn = 200005;

int n, m, k;
int r[Maxn];
vector <int> neigh[Maxn], rneigh[Maxn];
int in[Maxn], out[Maxn];
set <int> S;
int mn[Maxn], mx[Maxn];
priority_queue <ii> Q;

int main()
{
	scanf("%d %d %d", &n, &m, &k);
	for (int i = 1; i <= k; i++)
		S.insert(i);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &r[i]);
		if (r[i] > 0) { S.erase(r[i]); mn[i] = r[i]; mx[i] = r[i]; }
		else mn[i] = 1, mx[i] = k;
	}
	for (int i = 0; i < m; i++) {
		int a, b; scanf("%d %d", &a, &b);
		neigh[a].push_back(b);
		rneigh[b].push_back(a);
		out[a]++; in[b]++;
	}
	vector <int> seq;
	for (int i = 1; i <= n; i++)
		if (out[i] == 0) seq.push_back(i);
	for (int i = 0; i < seq.size(); i++) {
		int v = seq[i];
		if (r[v] > 0 && mn[v] > r[v]) { printf("-1\n"); return 0; }
		for (int j = 0; j < rneigh[v].size(); j++) {
			int u = rneigh[v][j];
			mn[u] = max(mn[u], mn[v] + 1);
			if (--out[u] == 0) seq.push_back(u);
		}
	}
	if (seq.size() < n) { printf("-1\n"); return 0; }
	for (int i = 1; i <= n; i++)
		if (in[i] == 0) Q.push(ii(mn[i], i));
	while (!Q.empty()) {
		int v = Q.top().second; Q.pop();
		bool was = r[v] > 0;
		if (!was) {
			set <int>::iterator it = S.upper_bound(mx[v]);
			if (it != S.begin()) {
				it--;
				if (mn[v] <= *it) { was = true; r[v] = mx[v] = *it;  S.erase(it); }
			}
			if (!was) r[v] = mx[v];
		}
		for (int j = 0; j < neigh[v].size(); j++) {
			int u = neigh[v][j];
			mx[u] = min(mx[u], mx[v] - 1);
			if (--in[u] == 0) Q.push(ii(mn[u], u));
		}
	}
	if (!S.empty()) { printf("-1\n"); return 0; }
	for (int i = 1; i <= n; i++)
		printf("%d%c", r[i], i + 1 <= n? ' ': '\n');
	return 0;
}


#include <cstdio>
#include <sstream>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <iostream>
#include <fstream>
#include <numeric>
#include <string>
#include <vector>
#include <cstring>
#include <map>
#include <iterator>
#include<complex>
//#include <bits/stdc++.h>

using namespace std;

#define HI              printf("HI\n")
#define sf              scanf
#define pf              printf
#define sf1(a)          scanf("%d",&a)
#define sf2(a,b)        scanf("%d %d",&a,&b)
#define sf3(a,b,c)      scanf("%d %d %d",&a,&b,&c)
#define sf4(a,b,c,d)    scanf("%d %d %d %d",&a,&b,&c,&d)
#define sf1ll(a)        scanf("%lld",&a)
#define sf2ll(a,b)      scanf("%lld %lld",&a,&b)
#define sf3ll(a,b,c)    scanf("%lld %lld %lld",&a,&b,&c)
#define sf4ll(a,b,c,d)    scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define forln(i,a,n)    for(int i=a ; i<n ; i++)
#define foren(i,a,n)    for(int i=a ; i<=n ; i++)
#define forg0(i,a,n)    for(int i=a ; i>n ; i--)
#define fore0(i,a,n)    for(int i=a ; i>=n ; i--)
#define pb              push_back
#define ppb             pop_back
#define ppf             push_front
#define popf            pop_front
#define ll              long long int
#define ui              unsigned int
#define ull             unsigned long long
#define fs              first
#define sc              second
#define clr( a, b )     memset((a),b,sizeof(a))
#define jora            pair<int, int>
#define jora_d          pair<double, double>
#define jora_ll         pair<long long int, long long int>
#define mp              make_pair
#define max3(a,b,c)     max(a,max(b,c))
#define min3(a,b,c)     min(a,min(b,c))
#define PI              acos(0.0)
#define ps              pf("PASS\n")
#define popc(a)         (__builtin_popcount(a))

template<class T1> void deb(T1 e1) {
    cout<<e1<<endl;
}
template<class T1,class T2> void deb(T1 e1,T2 e2) {
    cout<<e1<<" "<<e2<<endl;
}
template<class T1,class T2,class T3> void deb(T1 e1,T2 e2,T3 e3) {
    cout<<e1<<" "<<e2<<" "<<e3<<endl;
}
template<class T1,class T2,class T3,class T4> void deb(T1 e1,T2 e2,T3 e3,T4 e4) {
    cout<<e1<<" "<<e2<<" "<<e3<<" "<<e4<<endl;
}
template<class T1,class T2,class T3,class T4,class T5> void deb(T1 e1,T2 e2,T3 e3,T4 e4,T5 e5) {
    cout<<e1<<" "<<e2<<" "<<e3<<" "<<e4<<" "<<e5<<endl;
}
template<class T1,class T2,class T3,class T4,class T5,class T6> void deb(T1 e1,T2 e2,T3 e3,T4 e4,T5 e5,T6 e6) {
    cout<<e1<<" "<<e2<<" "<<e3<<" "<<e4<<" "<<e5<<" "<<e6<<endl;
}

/// <---------------------------  For Bitmasking  -------------------------------->
//int on( int n, int pos ){
//    return n = n|( 1<<pos );
//}
//bool check( int n, int pos ){
//    return (bool)( n&( 1<<pos ) );
//}
//int off( int n, int pos ){
//    return n = n&~( 1<<pos );
//}
//int toggle( int n, int pos ){
//    return n = n^(1<<pos);
//}
//int count_bit( int n ){
//    return __builtin_popcount( n );
//}
/// <---------------------------  End of Bitmasking  -------------------------------->

/// <--------------------------- For B - Base Number System ----------------------------------->
//int base;
//int pw[10];
//void calPow(int b){
//    base = b;
//    pw[0] = 1;
//    for( int i = 1; i<10; i++ ){
//        pw[i] = pw[i-1]*base;
//    }
//}
//int getV(int mask, int pos){
//    mask /= pw[pos];
//    return ( mask%base );
//}
//int setV(int mask, int v, int pos){
//    int rem = mask%pw[pos];
//    mask /= pw[pos+1];
//    mask = ( mask*base ) + v;
//    mask = ( mask*pw[pos] ) + rem;
//    return mask;
//}
/// <--------------------------- End B - Base Number System ----------------------------------->

// moves

//int dx[]= {0,0,1,-1};/*4 side move*/
//int dy[]= {-1,1,0,0};/*4 side move*/
//int dx[]= {1,1,0,-1,-1,-1,0,1};/*8 side move*/
//int dy[]= {0,1,1,1,0,-1,-1,-1};/*8 side move*/
//int dx[]={1,1,2,2,-1,-1,-2,-2};/*night move*/
//int dy[]={2,-2,1,-1,2,-2,1,-1};/*night move*/

//double Expo(double n, int p) {
//	if (p == 0)return 1;
//	double x = Expo(n, p >> 1);
//	x = (x * x);
//	return ((p & 1) ? (x * n) : x);
//}

//ll bigmod(ll a,ll b,ll m){if(b == 0) return 1%m;ll x = bigmod(a,b/2,m);x = (x * x) % m;if(b % 2 == 1) x = (x * a) % m;return x;}
//ll BigMod(ll B,ll P,ll M){ ll R=1%M; while(P>0) {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return R;} /// (B^P)%M

typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define MXN 50
#define MXE
#define MXQ
#define SZE
#define MOD
#define EPS
#define INF 100000000
#define MX  300005
#define inf 100000000

const ll mod = 1000000007ll;

vector<int> alive[MX];
vector<int> adj[MX];
vector<int> radj[MX];
int col[MX];
int val[MX];
int deg[MX];

bool possible(int n, int k) {
    queue<int> qu;
    for(int i = 1; i <= n; i++) {
        deg[i] = adj[i].size();
        if(deg[i] == 0) {
            qu.push(i);
            if(col[i] == 0) val[i] = 1;
            else val[i] = col[i];
        }
    }
    while(!qu.empty()) {
        int u = qu.front();
        qu.pop();
        if(col[u] != 0) {
            if(val[u]>col[u]) return false;
            val[u] = col[u];
        }
        for(int i = 0; i < radj[u].size(); i++) {
            int v = radj[u][i];
            deg[v]--;
            val[v] = max(val[v],val[u]+1);
            if(deg[v] == 0) {
                qu.push(v);
            }
        }
    }
    for(int i = 1; i <= n; i++) {
        if(val[i] == 0 || val[i] > k) return false;
    }
    return true;
}

int cnt[MX];

bool solve(int n, int k) {
    queue<int> qu;
    for(int i = 1; i <= n; i++) {
        deg[i] = radj[i].size();
        if(deg[i] == 0) {
            if(col[i] == 0)
                qu.push(i);
            else
                alive[col[i]].push_back(i);
        }
        cnt[val[i]]++;
    }
    int make = k;
    while(make>0) {
        while(make>0 && cnt[make] != 0) {
            for(int i = 0; i < alive[make].size(); i++)
                qu.push(alive[make][i]);
            make--;
        }
        //deb("make", make);
        if(qu.empty()) return false;
        int u = qu.front();
        qu.pop();
        //deb("node", u);
        for(int i = 0; i < adj[u].size(); i++) {
            int v = adj[u][i];
            deg[v]--;
            if(deg[v] == 0) {
                if(col[v] == 0 || col[v]>=make)
                    qu.push(v);
                else {
                    alive[col[v]].push_back(v);
                }
            }
        }
        if(make == 0) continue;
        if(val[u]>make || col[u] != 0) continue;
        cnt[val[u]]--;
        val[u] = make;
        cnt[val[u]]++;
    }
    memset(deg,0,sizeof deg);
    for(int i = 1; i <= n; i++)
        deg[val[i]]++;
    for(int i = 1; i <= k; i++)
        if(deg[i] == 0) return false;
    return true;
}

int main() {
//    ios_base::sync_with_stdio(0);
//    freopen("input.txt", "r", stdin);
    int n, m, k, u, v;
    scanf("%d %d %d", &n, &m, &k);
    for(int i = 1; i <= n; i++) {
        scanf("%d", &col[i]);
    }
    for(int i = 1; i <= m; i++) {
        scanf("%d %d", &u, &v);
        adj[u].push_back(v);
        radj[v].push_back(u);
    }
    if(!possible(n,k)) {
        puts("-1");
        return 0;
    }
//    for(int i = 1; i <= n; i++)
//        deb(">>>", i,val[i]);
    if(!solve(n,k)) {
        puts("-1");
        return 0;
    }
    for(int i = 1; i <= n; i++)
        printf("%d ", val[i]);
    puts("");
    return 0;
}


#include <cstdio>
#include <sstream>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <iostream>
#include <fstream>
#include <numeric>
#include <string>
#include <vector>
#include <cstring>
#include <map>
#include <iterator>
#include<complex>
//#include <bits/stdc++.h>

using namespace std;

#define HI              printf("HI\n")
#define sf              scanf
#define pf              printf
#define sf1(a)          scanf("%d",&a)
#define sf2(a,b)        scanf("%d %d",&a,&b)
#define sf3(a,b,c)      scanf("%d %d %d",&a,&b,&c)
#define sf4(a,b,c,d)    scanf("%d %d %d %d",&a,&b,&c,&d)
#define sf1ll(a)        scanf("%lld",&a)
#define sf2ll(a,b)      scanf("%lld %lld",&a,&b)
#define sf3ll(a,b,c)    scanf("%lld %lld %lld",&a,&b,&c)
#define sf4ll(a,b,c,d)    scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define forln(i,a,n)    for(int i=a ; i<n ; i++)
#define foren(i,a,n)    for(int i=a ; i<=n ; i++)
#define forg0(i,a,n)    for(int i=a ; i>n ; i--)
#define fore0(i,a,n)    for(int i=a ; i>=n ; i--)
#define pb              push_back
#define ppb             pop_back
#define ppf             push_front
#define popf            pop_front
#define ll              long long int
#define ui              unsigned int
#define ull             unsigned long long
#define fs              first
#define sc              second
#define clr( a, b )     memset((a),b,sizeof(a))
#define jora            pair<int, int>
#define jora_d          pair<double, double>
#define jora_ll         pair<long long int, long long int>
#define mp              make_pair
#define max3(a,b,c)     max(a,max(b,c))
#define min3(a,b,c)     min(a,min(b,c))
#define PI              acos(0.0)
#define ps              pf("PASS\n")
#define popc(a)         (__builtin_popcount(a))

template<class T1> void deb(T1 e1) {
    cout<<e1<<endl;
}
template<class T1,class T2> void deb(T1 e1,T2 e2) {
    cout<<e1<<" "<<e2<<endl;
}
template<class T1,class T2,class T3> void deb(T1 e1,T2 e2,T3 e3) {
    cout<<e1<<" "<<e2<<" "<<e3<<endl;
}
template<class T1,class T2,class T3,class T4> void deb(T1 e1,T2 e2,T3 e3,T4 e4) {
    cout<<e1<<" "<<e2<<" "<<e3<<" "<<e4<<endl;
}
template<class T1,class T2,class T3,class T4,class T5> void deb(T1 e1,T2 e2,T3 e3,T4 e4,T5 e5) {
    cout<<e1<<" "<<e2<<" "<<e3<<" "<<e4<<" "<<e5<<endl;
}
template<class T1,class T2,class T3,class T4,class T5,class T6> void deb(T1 e1,T2 e2,T3 e3,T4 e4,T5 e5,T6 e6) {
    cout<<e1<<" "<<e2<<" "<<e3<<" "<<e4<<" "<<e5<<" "<<e6<<endl;
}

/// <---------------------------  For Bitmasking  -------------------------------->
//int on( int n, int pos ){
//    return n = n|( 1<<pos );
//}
//bool check( int n, int pos ){
//    return (bool)( n&( 1<<pos ) );
//}
//int off( int n, int pos ){
//    return n = n&~( 1<<pos );
//}
//int toggle( int n, int pos ){
//    return n = n^(1<<pos);
//}
//int count_bit( int n ){
//    return __builtin_popcount( n );
//}
/// <---------------------------  End of Bitmasking  -------------------------------->

/// <--------------------------- For B - Base Number System ----------------------------------->
//int base;
//int pw[10];
//void calPow(int b){
//    base = b;
//    pw[0] = 1;
//    for( int i = 1; i<10; i++ ){
//        pw[i] = pw[i-1]*base;
//    }
//}
//int getV(int mask, int pos){
//    mask /= pw[pos];
//    return ( mask%base );
//}
//int setV(int mask, int v, int pos){
//    int rem = mask%pw[pos];
//    mask /= pw[pos+1];
//    mask = ( mask*base ) + v;
//    mask = ( mask*pw[pos] ) + rem;
//    return mask;
//}
/// <--------------------------- End B - Base Number System ----------------------------------->

// moves

//int dx[]= {0,0,1,-1};/*4 side move*/
//int dy[]= {-1,1,0,0};/*4 side move*/
//int dx[]= {1,1,0,-1,-1,-1,0,1};/*8 side move*/
//int dy[]= {0,1,1,1,0,-1,-1,-1};/*8 side move*/
//int dx[]={1,1,2,2,-1,-1,-2,-2};/*night move*/
//int dy[]={2,-2,1,-1,2,-2,1,-1};/*night move*/

//double Expo(double n, int p) {
//	if (p == 0)return 1;
//	double x = Expo(n, p >> 1);
//	x = (x * x);
//	return ((p & 1) ? (x * n) : x);
//}

//ll bigmod(ll a,ll b,ll m){if(b == 0) return 1%m;ll x = bigmod(a,b/2,m);x = (x * x) % m;if(b % 2 == 1) x = (x * a) % m;return x;}
//ll BigMod(ll B,ll P,ll M){ ll R=1%M; while(P>0) {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return R;} /// (B^P)%M

typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define MXN 50
#define MXE
#define MXQ
#define SZE
#define MOD
#define EPS
#define INF 100000000
#define MX  300005
#define inf 100000000

const ll mod = 1000000007ll;

vector<int> alive[MX];
vector<int> adj[MX];
vector<int> radj[MX];
int col[MX];
int val[MX];
int deg[MX];

bool possible(int n, int k) {
    queue<int> qu;
    for(int i = 1; i <= n; i++) {
        deg[i] = adj[i].size();
        if(deg[i] == 0) {
            qu.push(i);
            if(col[i] == 0) val[i] = 1;
            else val[i] = col[i];
        }
    }
    while(!qu.empty()) {
        int u = qu.front();
        qu.pop();
        if(col[u] != 0) {
            if(val[u]>col[u]) return false;
            val[u] = col[u];
        }
        for(int i = 0; i < radj[u].size(); i++) {
            int v = radj[u][i];
            deg[v]--;
            val[v] = max(val[v],val[u]+1);
            if(deg[v] == 0) {
                qu.push(v);
            }
        }
    }
    for(int i = 1; i <= n; i++) {
        if(val[i] == 0 || val[i] > k) return false;
    }
    return true;
}

int cnt[MX];

bool solve(int n, int k) {
    priority_queue<pii> qu;
    for(int i = 1; i <= n; i++) {
        deg[i] = radj[i].size();
        if(deg[i] == 0) {
            if(col[i] == 0)
                qu.push(make_pair(val[i],i));
            else
                alive[col[i]].push_back(i);
        }
        cnt[val[i]]++;
    }
    int make = k;
    while(make>0) {
        while(make>0 && cnt[make] != 0) {
            for(int i = 0; i < alive[make].size(); i++)
                qu.push(make_pair(val[alive[make][i]], alive[make][i]));
            make--;
        }
        //deb("make", make);
        if(qu.empty()) return false;
        int u = qu.top().second;
        qu.pop();
        //deb("node", u);
        for(int i = 0; i < adj[u].size(); i++) {
            int v = adj[u][i];
            deg[v]--;
            if(deg[v] == 0) {
                if(col[v] == 0 || col[v]>=make)
                    qu.push(make_pair(val[v],v));
                else {
                    alive[col[v]].push_back(v);
                }
            }
        }
        if(make == 0) continue;
        if(val[u]>=make || col[u] != 0) continue;
        cnt[val[u]]--;
        val[u] = make;
        cnt[val[u]]++;
    }
    memset(deg,0,sizeof deg);
    for(int i = 1; i <= n; i++)
        deg[val[i]]++;
    for(int i = 1; i <= k; i++)
        if(deg[i] == 0) return false;
    return true;
}

int main() {
//    ios_base::sync_with_stdio(0);
//    freopen("input.txt", "r", stdin);
    int n, m, k, u, v;
    scanf("%d %d %d", &n, &m, &k);
    for(int i = 1; i <= n; i++) {
        scanf("%d", &col[i]);
    }
    for(int i = 1; i <= m; i++) {
        scanf("%d %d", &u, &v);
        adj[u].push_back(v);
        radj[v].push_back(u);
    }
    if(!possible(n,k)) {
        puts("-1");
        return 0;
    }
//    for(int i = 1; i <= n; i++)
//        deb(">>>", i,val[i]);
    if(!solve(n,k)) {
        puts("-1");
        return 0;
    }
    for(int i = 1; i <= n; i++)
        printf("%d ", val[i]);
    puts("");
    return 0;
}

/**
20 20 20
0 0 14 0 0 0 0 0 0 0 0 0 0 13 0 0 0 0 0 0
8 20
8 3
8 16
3 14
7 2
19 10
5 14
18 20
8 15
5 16
7 10
13 18
7 17
7 17
7 20
2 6
8 18
16 14
2 15
6 11
*/


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

int n,m,k;
int a[202000],b[202000],l[202000],r[202000],used[202000];

vector<int>G[202000];
int deg[202000],q[202000],he,ta;

struct P{
	int id,st,en;
}p[202000];
bool cp(P p1,P p2){
	return p1.st<p2.st;
}
struct cmp{
	bool operator ()(P p1,P p2){
		return p1.en>p2.en;
	}
};
priority_queue<P,vector<P>,cmp>pq;

int main(){
	scanf("%d%d%d",&n,&m,&k);
	if (k>n) return 0*puts("-1");
	for (int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		used[a[i]]=1;
		b[i]=a[i];
		if (b[i]){
			l[i]=r[i]=a[i];
		}else{
			l[i]=1;r[i]=k;
		}
	}
	int x,y;
	for (int i=1;i<=m;i++){
		scanf("%d%d",&x,&y);
		G[x].push_back(y);
		deg[y]++;
	}
	he=ta=0;
	for (int i=1;i<=n;i++){
		if (!deg[i])
			q[++ta]=i;
	}
	int now;
	for (;he<ta;){
		now=q[++he];
		for (int i=0;i<(int)G[now].size();i++){
			y=G[now][i];
			if (!--deg[y])
				q[++ta]=y;
		}
	}
	if (ta<n) return 0*printf("-1");

	for (int j=1;j<=n;j++){
		now=q[j];
		for (int i=0;i<(int)G[now].size();i++){
			y=G[now][i];
			r[y]=min(r[y],r[now]-1);
		}
	}
	for (int j=n;j>0;j--){
		now=q[j];
		for (int i=0;i<(int)G[now].size();i++){
			y=G[now][i];
			l[now]=max(l[now],l[y]+1);
			if (l[now]>r[now]) return 0*printf("-1");
		}
	}
	for (int i=1;i<=n;i++){
		p[i]=(P){i,l[i],r[i]};
	}
	sort(p+1,p+n+1,cp);
	//for (int i=1;i<=n;i++)printf("%d::%d-%d\n",i,l[i],r[i]);
	int pos=0,fl;
	for (int i=1;i<=k;i++){
		while (pos<n&&p[pos+1].st<=i) pq.push(p[++pos]);
		fl=used[i];
		for (;!pq.empty();){
			if (pq.top().en==i||!fl){
				a[pq.top().id]=i;
				pq.pop();
			}else{
				break;
			}
			fl=1;
		}
		if (!fl) return 0*printf("-1");
	}
	//printf("\n(%d)\n",pos);
	//for (int i=1;i<=n;i++) printf("%d ",a[i]);printf("\n");

	for (int j=1;j<=n;j++){
		now=q[j];
		for (int i=0;i<(int)G[now].size();i++){
			y=G[now][i];
			a[y]=min(a[y],a[now]-1);
		}
		if (b[now]&&a[now]!=b[now]) return 0*printf("-1");
	}
	for (int i=1;i<=n;i++) printf("%d ",a[i]);
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 2e+5+5;

int n,m,k;
int rk[N];
struct edge{
	int x,nxt;
}e1[N],e2[N];
int h1[N],h2[N],tot1,tot2;
bool bz[N];
int Rig[N],Lef[N];
int que[N],r[N];

void inse1(int x,int y){e1[++tot1].x=y;e1[tot1].nxt=h1[x];h1[x]=tot1;}

void inse2(int x,int y){e2[++tot2].x=y;e2[tot2].nxt=h2[x];h2[x]=tot2;}

bool cmp(int x,int y){return Rig[x]>Rig[y];}

int main(){
	n=get();m=get();k=get();
	fo(i,1,n)bz[rk[i]=get()]=1;
	fo(i,1,m){
		int x=get(),y=get();
		inse1(x,y);
		inse2(y,x);
		r[y]++;
	}
	int he=0,ta=0;
	fo(i,1,n)Rig[i]=k;
	fo(i,1,n)
	if (!r[i])que[++ta]=i;
	for(;he<ta;){
		int x=que[++he];
		if (rk[x])Rig[x]=min(Rig[x],rk[x]);
		for(int p=h1[x];p;p=e1[p].nxt){
			r[e1[p].x]--;
			Rig[e1[p].x]=min(Rig[e1[p].x],Rig[x]-1);
			if (!r[e1[p].x])que[++ta]=e1[p].x;
		}
	}
	if (ta!=n)return printf("-1\n"),0;
	int w=1;
	for(;bz[w];w++);
	sort(que+1,que+1+n,cmp);
	fd(i,n,1){
		int x=que[i];
		if (w<=Rig[x]&&!rk[x]){
			rk[x]=w;
			bz[w]=1;
			for(;bz[w];w++);
		}
		else{
			if (rk[x]){
				if(rk[x]<Lef[x])return printf("-1\n"),0;
			}
			else rk[x]=max(1,Lef[x]);
		}
		if (rk[x]>Rig[x])return printf("-1\n"),0;
		for(int p=h2[x];p;p=e2[p].nxt)
			Lef[e2[p].x]=max(Lef[e2[p].x],rk[x]+1);
	}
	if (w<=k)return printf("-1\n"),0;
	fo(i,1,n)printf("%d ",rk[i]);
	return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 2e+5+5;

int n,m,k;
int rk[N];
struct edge{
	int x,nxt;
}e1[N],e2[N];
int h1[N],h2[N],tot1,tot2;
bool bz[N];
int Rig[N],Lef[N];
int que[N],r[N];

void inse1(int x,int y){e1[++tot1].x=y;e1[tot1].nxt=h1[x];h1[x]=tot1;}

void inse2(int x,int y){e2[++tot2].x=y;e2[tot2].nxt=h2[x];h2[x]=tot2;}

int main(){
	n=get();m=get();k=get();
	fo(i,1,n)bz[rk[i]=get()]=1;
	fo(i,1,m){
		int x=get(),y=get();
		inse1(x,y);
		inse2(y,x);
		r[y]++;
	}
	int he=0,ta=0;
	fo(i,1,n)Rig[i]=k;
	fo(i,1,n)
	if (!r[i])que[++ta]=i;
	for(;he<ta;){
		int x=que[++he];
		if (rk[x])Rig[x]=min(Rig[x],rk[x]);
		for(int p=h1[x];p;p=e1[p].nxt){
			r[e1[p].x]--;
			Rig[e1[p].x]=min(Rig[e1[p].x],Rig[x]-1);
			if (!r[e1[p].x])que[++ta]=e1[p].x;
		}
	}
	if (ta!=n)return printf("-1\n"),0;
	int w=1;
	for(;bz[w];w++);
	fd(i,n,1){
		int x=que[i];
		if (w<=Rig[x]&&!rk[x]){
			rk[x]=w;
			bz[w]=1;
			for(;bz[w];w++);
		}
		else{
			if (rk[x]){
				if(rk[x]<Lef[x])return printf("-1\n"),0;
			}
			else rk[x]=max(1,Lef[x]);
		}
		if (rk[x]>Rig[x])return printf("-1\n"),0;
		for(int p=h2[x];p;p=e2[p].nxt)
			Lef[e2[p].x]=max(Lef[e2[p].x],rk[x]+1);
	}
	if (w<=k)return printf("-1\n"),0;
	fo(i,1,n)printf("%d ",rk[i]);
	return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 2e+5+5;

int n,m,k;
int rk[N];
struct edge{
	int x,nxt;
}e1[N],e2[N];
int h1[N],h2[N],tot1,tot2;
bool bz[N];
int Rig[N],Lef[N];
int que[N],r[N];

void inse1(int x,int y){e1[++tot1].x=y;e1[tot1].nxt=h1[x];h1[x]=tot1;}

void inse2(int x,int y){e2[++tot2].x=y;e2[tot2].nxt=h2[x];h2[x]=tot2;}

bool cmp(int x,int y){return Rig[x]>Rig[y];}

int main(){
	n=get();m=get();k=get();
	fo(i,1,n)bz[rk[i]=get()]=1;
	fo(i,1,m){
		int x=get(),y=get();
		inse1(x,y);
		inse2(y,x);
		r[y]++;
	}
	int he=0,ta=0;
	fo(i,1,n)Rig[i]=k;
	fo(i,1,n)
	if (!r[i])que[++ta]=i;
	for(;he<ta;){
		int x=que[++he];
		if (rk[x])Rig[x]=min(Rig[x],rk[x]);
		for(int p=h1[x];p;p=e1[p].nxt){
			r[e1[p].x]--;
			Rig[e1[p].x]=min(Rig[e1[p].x],Rig[x]-1);
			if (!r[e1[p].x])que[++ta]=e1[p].x;
		}
	}
	if (ta!=n)return printf("-1\n"),0;
	sort(que+1,que+1+n,cmp);
	set<int>s;
	s.clear();
	fo(i,1,k)
	if (!bz[i])s.insert(i);
	fd(i,n,1){
		int x=que[i];
		if (!rk[x]){
			set<int>::iterator h=s.lower_bound(Lef[x]);
			if((h!=s.end())&&(*h)<=Rig[x]){
				bz[rk[x]=(*h)]=1;
				s.erase(h);
			}
			else rk[x]=max(1,Lef[x]);
		}
		if (rk[x]<Lef[x])return printf("-1\n"),0;
		if (rk[x]>Rig[x])return printf("-1\n"),0;
		for(int p=h2[x];p;p=e2[p].nxt)
			Lef[e2[p].x]=max(Lef[e2[p].x],rk[x]+1);
	}
	fo(i,1,k)
	if (!bz[i])return printf("-1\n"),0;
	fo(i,1,n)printf("%d ",rk[i]);
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#define pb push_back
#define rep(i,a,b) for(i=a;i<=b;i++)
using namespace std;
const int N=200010;
int rk[N],down[N],up[N],a[N];int in[N],out[N];
int q[N],h,t;
int n,m,K;
vector<int> vec[N];
vector<int> vi[N],vo[N];

struct data{
	int w,x;
	data(){}
	data(int w,int x):w(w),x(x){}
	friend bool operator < (data aa,data bb){return aa.w>bb.w;}
};
priority_queue<data> minh;

void work(int x,int now){
	int i,y;
	rk[x]=now;
	rep(i,0,(int)vi[x].size()-1){
		y=vi[x][i];
		down[y]=max(down[y],rk[x]+1);
		in[y]--;
		if(!in[y])	vec[down[y]].pb(y);
	}
}

int main(){
//	freopen("a.in","r",stdin);
//	freopen("a.out","w",stdout);
	int i,x,y,j;
	scanf("%d%d%d",&n,&m,&K);
	rep(i,1,n)	scanf("%d",&a[i]);
	rep(i,1,n)	if(a[i])	up[i]=a[i];else up[i]=K;
	rep(i,1,m){
		scanf("%d%d",&x,&y);swap(x,y);
		out[x]++;vo[y].pb(x);
		in[y]++;vi[x].pb(y);
	}
	h=t=0;
	rep(i,1,n)	if(out[i]==0)	q[++t]=i;
	while(h<t){
		x=q[++h];
		rep(i,0,(int)vo[x].size()-1){
			y=vo[x][i];
			out[y]--;
			up[y]=min(up[y],up[x]-1);
			if(!out[y])	q[++t]=y;
		}
	}
	rep(i,1,n)	if(a[i]&&up[i]<a[i])	{printf("-1\n");return 0;}
	rep(i,1,n)	if(up[i]<1)	{printf("-1\n");return 0;}
	rep(i,1,n)	if(a[i])	down[i]=a[i];else down[i]=1;
	rep(i,1,n)	if(!in[i])	vec[down[i]].pb(i);
	rep(i,1,K){
		rep(j,0,(int)vec[i].size()-1){
			x=vec[i][j];
			minh.push(data(up[x],x));
		}
		if(minh.empty())	{printf("-1\n");return 0;}
		work(minh.top().x,i);minh.pop();
		while(!minh.empty()&&minh.top().w==i){
			work(minh.top().x,i);minh.pop();
		}
	}
	rep(i,1,n)	printf("%d ",rk[i]);
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#define pb push_back
#define rep(i,a,b) for(i=a;i<=b;i++)
using namespace std;
const int N=200010;
int rk[N],down[N],up[N],a[N];int in[N],out[N];
int q[N],h,t;
int n,m,K;
vector<int> vec[N];
vector<int> vi[N],vo[N];

struct data{
	int w,x;
	data(){}
	data(int w,int x):w(w),x(x){}
	friend bool operator < (data aa,data bb){return aa.w>bb.w;}
};
priority_queue<data> minh;

void work(int x,int now){
	int i,y;
	rk[x]=now;
	rep(i,0,(int)vi[x].size()-1){
		y=vi[x][i];
		down[y]=max(down[y],rk[x]+1);
		in[y]--;
		if(!in[y])	vec[down[y]].pb(y);
	}
}

int main(){
//	freopen("a.in","r",stdin);
//	freopen("a.out","w",stdout);
	int i,x,y,j;
	scanf("%d%d%d",&n,&m,&K);
	rep(i,1,n)	scanf("%d",&a[i]);
	rep(i,1,n)	if(a[i])	up[i]=a[i];else up[i]=K;
	rep(i,1,m){
		scanf("%d%d",&x,&y);swap(x,y);
		out[x]++;vo[y].pb(x);
		in[y]++;vi[x].pb(y);
	}
	h=t=0;
	rep(i,1,m)	if(out[i]==0)	q[++t]=i;
	while(h<t){
		x=q[++h];
		rep(i,0,(int)vo[x].size()-1){
			y=vo[x][i];
			out[y]--;
			up[y]=min(up[y],up[x]-1);
			if(!out[y])	q[++t]=y;
		}
	}
	rep(i,1,n)	if(a[i]&&up[i]<a[i])	{printf("-1\n");return 0;}
	rep(i,1,n)	if(up[i]<1)	{printf("-1\n");return 0;}
	rep(i,1,n)	if(a[i])	down[i]=a[i];else down[i]=1;
	rep(i,1,n)	if(!in[i])	vec[down[i]].pb(i);
	rep(i,1,K){
		rep(j,0,(int)vec[i].size()-1){
			x=vec[i][j];
			minh.push(data(up[x],x));
		}
		if(minh.empty())	{printf("-1\n");return 0;}
		work(minh.top().x,i);minh.pop();
		while(!minh.empty()&&minh.top().w==i){
			work(minh.top().x,i);minh.pop();
		}
	}
	rep(i,1,n)	printf("%d ",rk[i]);
}


#include<cstdio>
#include<cstdlib>
#include<queue>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
typedef pair<int,pair<int,int> > PI;
const int N=200005;
int n,m,k;
int a[N];
bool o[N];//是不是一开始有有数了
struct qq
{
	int x,y,last;
}e[N];int num,last[N];
qq E[N];int Last[N];
int d[N],D[N];
void init (int x,int y)
{
	num++;d[y]++;
	e[num].x=x;e[num].y=y;
	e[num].last=last[x];
	last[x]=num;

	swap(x,y);
	D[y]++;
	E[num].x=x;E[num].y=y;
	E[num].last=Last[x];
	Last[x]=num;
}
priority_queue<PI,vector<PI>,greater<PI> >Q;
int tt[N];
int g[N];
void solve1 ()
{
/*	for (int i=1;i<=n;i++) printf("%d ",a[i]);
			printf("\n");*/
	memset(g,0,sizeof(g));
	for (int u=1;u<=n;u++)
	{
		if (D[u]==0)
		{
			Q.push(make_pair(1,make_pair(a[u],u)));
			g[u]=1;
		}
		tt[a[u]]++;
	}
	for (int u=1;u<=k;u++)
		if (tt[u]==0)//如果这个颜色不存在
		{
			while (!Q.empty())
			{
				int x=Q.top().first,xx=Q.top().second.second;Q.pop();
				if (x>u) break;
				if (a[xx]<u||o[xx])
				{
					for (int i=Last[xx];i!=-1;i=E[i].last)
					{
						int y=E[i].y;
						D[y]--;
						g[y]=max(g[y],a[xx]+1);
						if (D[y]==0)
							Q.push(make_pair(g[y],make_pair(a[y],y)));
					}
					continue;
				}
				else
				{
					tt[a[xx]]--;
					a[xx]=u;
					tt[u]++;
					for (int i=Last[xx];i!=-1;i=E[i].last)
					{
						int y=E[i].y;
						D[y]--;
						g[y]=max(g[y],a[xx]+1);
						if (D[y]==0)
							Q.push(make_pair(g[y],make_pair(a[y],y)));
					}
					break;
				}
			}
		/*	for (int i=1;i<=n;i++) printf("%d ",a[i]);
			printf("\n");
			system("pause");*/
			if (tt[u]==0) {printf("-1");return ;}
		}
	for (int u=1;u<=n;u++) printf("%d ",a[u]);
}
queue<int> q;
void solve ()
{
	int tot=0;
	for (int u=1;u<=n;u++)
		if (d[u]==0)
		{
			q.push(u);
			if (o[u]==false) a[u]=k;
		}
/*	for (int u=1;u<=n;u++) printf("%d ",a[u]);
		printf("\n");*/
	while (!q.empty())
	{
		tot++;int x=q.front();
		for (int u=last[x];u!=-1;u=e[u].last)
		{
			int y=e[u].y;
			if (o[y])
			{
				if (a[y]>=a[x])
				{
					printf("-1");
					return ;
				}
			}
			else	a[y]=min(a[y],a[x]-1);
			d[y]--;
			if (d[y]==0)	q.push(y);
		}
		//printf("%d\n",x);
		q.pop();/*
		*/
	}
	for (int u=1;u<=n;u++)
		if (a[u]<=0)
		{
			printf("-1");
			return ;
		}

	if (tot!=n)
	{
		printf("-1");
		return ;
	}/*for (int u=1;u<=n;u++) printf("%d ",a[u]);
		printf("\n");*/
	solve1();
}
int main()
{
	num=0;memset(last,-1,sizeof(last));
	memset(Last,-1,sizeof(Last));
	scanf("%d%d%d",&n,&m,&k);
	for (int u=1;u<=n;u++)
	{
		scanf("%d",&a[u]);
		if (a[u]==0)
		{
			a[u]=k+1;
			o[u]=false;
		}
		else o[u]=true;
	}
	for (int u=1;u<=m;u++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		init(x,y);
	}
	solve();
	return 0;
}


#include<cstdio>
#include<queue>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
typedef pair<int,int> PI;
const int N=200005;
int n,m,k;
int a[N];
bool o[N];//是不是一开始有有数了
struct qq
{
	int x,y,last;
}e[N];int num,last[N];
qq E[N];int Last[N];
int d[N],D[N];
void init (int x,int y)
{
	num++;d[y]++;
	e[num].x=x;e[num].y=y;
	e[num].last=last[x];
	last[x]=num;

	swap(x,y);
	D[y]++;
	E[num].x=x;E[num].y=y;
	E[num].last=Last[x];
	Last[x]=num;
}
priority_queue<PI,vector<PI>,greater<PI> >Q;
int tt[N];
int g[N];
void solve1 ()
{
	memset(g,0,sizeof(g));
	for (int u=1;u<=n;u++)
	{
		if (D[u]==0)
		{
			Q.push(make_pair(1,u));
			g[u]=1;
		}
		tt[a[u]]++;
	}
	for (int u=1;u<=k;u++)
		if (tt[u]==0)//如果这个颜色不存在
		{
			while (!Q.empty())
			{
				int x=Q.top().first,xx=Q.top().second;Q.pop();
				//printf("%d %d %d %d\n",u,x,xx,a[xx]);
				if (a[xx]<u) continue;
				if (x>u) break;
				if (o[xx])
				{
					for (int i=Last[xx];i!=-1;i=E[i].last)
					{
						int y=E[i].y;
						D[y]--;
						g[y]=max(g[y],a[xx]+1);
						if (D[y]==0)
							Q.push(make_pair(g[y],y));
					}
				}
				else
				{
					tt[a[xx]]--;
					a[xx]=u;
					tt[u]++;
					for (int i=Last[xx];i!=-1;i=E[i].last)
					{
						int y=E[i].y;
						D[y]--;
						g[y]=max(g[y],a[xx]+1);
						if (D[y]==0)
							Q.push(make_pair(g[y],y));
					}
					break;
				}
			}
			if (tt[u]==0) {printf("-1");return ;}
		}
	for (int u=1;u<=n;u++) printf("%d ",a[u]);
}
queue<int> q;
void solve ()
{
	int tot=0;
	for (int u=1;u<=n;u++)
		if (d[u]==0)
		{
			q.push(u);
			if (o[u]==false) a[u]=k;
		}

	while (!q.empty())
	{
		tot++;int x=q.front();
		for (int u=last[x];u!=-1;u=e[u].last)
		{
			int y=e[u].y;
			if (o[y])
			{
				if (a[y]>=a[x])
				{
					printf("-1");
					return ;
				}
			}
			else	a[y]=min(a[y],a[x]-1);
			d[y]--;
			if (d[y]==0)	q.push(y);
		}
		q.pop();
	}
	for (int u=1;u<=n;u++)
		if (a[u]<=0)
		{
			printf("-1");
			return ;
		}
	if (tot!=n)
	{
		printf("-1");
		return ;
	}
	solve1();
}
int main()
{
	num=0;memset(last,-1,sizeof(last));
	memset(Last,-1,sizeof(Last));
	scanf("%d%d%d",&n,&m,&k);
	for (int u=1;u<=n;u++)
	{
		scanf("%d",&a[u]);
		if (a[u]==0)
		{
			a[u]=k+1;
			o[u]=false;
		}
		else o[u]=true;
	}
	for (int u=1;u<=m;u++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		init(x,y);
	}
	solve();
	return 0;
}


#include<cstdio>
#include<queue>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
typedef pair<int,int> PI;
const int N=200005;
int n,m,k;
int a[N];
bool o[N];//是不是一开始有有数了
struct qq
{
	int x,y,last;
}e[N];int num,last[N];
qq E[N];int Last[N];
int d[N],D[N];
void init (int x,int y)
{
	num++;d[y]++;
	e[num].x=x;e[num].y=y;
	e[num].last=last[x];
	last[x]=num;

	swap(x,y);
	D[y]++;
	E[num].x=x;E[num].y=y;
	E[num].last=Last[x];
	Last[x]=num;
}
priority_queue<PI,vector<PI>,greater<PI> >Q;
int tt[N];
int g[N];
void solve1 ()
{
	memset(g,0,sizeof(g));
	for (int u=1;u<=n;u++)
	{
		if (D[u]==0)
		{
			Q.push(make_pair(1,u));
			g[u]=1;
		}
		tt[a[u]]++;
	}
	for (int u=1;u<=k;u++)
		if (tt[u]==0)//如果这个颜色不存在
		{
			while (!Q.empty())
			{
				int x=Q.top().first,xx=Q.top().second;Q.pop();
				//printf("%d %d %d %d\n",u,x,xx,a[xx]);
				if (a[xx]<u) continue;
				if (x>u) break;
				if (o[xx])
				{
					for (int i=Last[xx];i!=-1;i=E[i].last)
					{
						int y=E[i].y;
						D[y]--;
						g[y]=max(g[y],a[xx]+1);
						if (D[y]==0)
							Q.push(make_pair(g[y],y));
					}
				}
				else
				{
					tt[a[xx]]--;
					a[xx]=u;
					tt[u]++;
					for (int i=Last[xx];i!=-1;i=E[i].last)
					{
						int y=E[i].y;
						D[y]--;
						g[y]=max(g[y],a[xx]+1);
						if (D[y]==0)
							Q.push(make_pair(g[y],y));
					}
					break;
				}
			}
			if (tt[u]==0) {printf("-1");return ;}
		}
	for (int u=1;u<=n;u++) printf("%d ",a[u]);
}
queue<int> q;
void solve ()
{
	int tot=0;
	for (int u=1;u<=n;u++)
		if (d[u]==0)
		{
			q.push(u);
			if (o[u]==false) a[u]=k;
		}

	while (!q.empty())
	{
		tot++;int x=q.front();
		for (int u=last[x];u!=-1;u=e[u].last)
		{
			int y=e[u].y;
			if (o[y])
			{
				if (a[y]>=a[x])
				{
					printf("-1");
					return ;
				}
			}
			else	a[y]=min(a[y],a[x]-1);
			d[y]--;
			if (d[y]==0)	q.push(y);
		}
		q.pop();
	}/*for (int u=1;u<=n;u++) printf("%d ",a[u]);
	printf("\n");*/
	if (tot!=n)
	{
		printf("-1");
		return ;
	}
	solve1();
}
int main()
{
	num=0;memset(last,-1,sizeof(last));
	memset(Last,-1,sizeof(Last));
	scanf("%d%d%d",&n,&m,&k);
	for (int u=1;u<=n;u++)
	{
		scanf("%d",&a[u]);
		if (a[u]==0)
		{
			a[u]=k+1;
			o[u]=false;
		}
		else o[u]=true;
	}
	for (int u=1;u<=m;u++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		init(x,y);
	}
	solve();
	return 0;
}


#include<cstdio>
#include<cstdlib>
#include<queue>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
typedef pair<int,int> PI;
const int N=200005;
int n,m,k;
int a[N];
bool o[N];//是不是一开始有有数了
struct qq
{
	int x,y,last;
}e[N];int num,last[N];
qq E[N];int Last[N];
int d[N],D[N];
void init (int x,int y)
{
	num++;d[y]++;
	e[num].x=x;e[num].y=y;
	e[num].last=last[x];
	last[x]=num;

	swap(x,y);
	D[y]++;
	E[num].x=x;E[num].y=y;
	E[num].last=Last[x];
	Last[x]=num;
}
priority_queue<PI,vector<PI>,greater<PI> >Q,Q1 ;
int tt[N];
int g[N];
void solve1 ()
{
/*	for (int i=1;i<=n;i++) printf("%d ",a[i]);
			printf("\n");*/
	memset(g,0,sizeof(g));
	for (int u=1;u<=n;u++)
	{
		if (D[u]==0)
		{
			Q.push(make_pair(a[u],u));
			g[u]=1;
		}
		tt[a[u]]++;
	}
	for (int u=1;u<=k;u++)
		if (tt[u]==0)//如果这个颜色不存在
		{
			while (!Q1.empty())
			{
				int x=Q1.top().first,y=Q1.top().second;
				if (x>u) break;
				Q1.pop();Q.push(make_pair(a[y],y));
			}
			while (!Q.empty())
			{
				int x=Q.top().first,xx=Q.top().second;Q.pop();
				if (x<u||o[xx])
				{
					for (int i=Last[xx];i!=-1;i=E[i].last)
					{
						int y=E[i].y;
						D[y]--;
						g[y]=max(g[y],a[xx]+1);
						if (D[y]==0)
							Q1.push(make_pair(g[y],y));
					}
					continue;
				}
				else
				{
					tt[a[xx]]--;
					a[xx]=u;
					tt[u]++;
					for (int i=Last[xx];i!=-1;i=E[i].last)
					{
						int y=E[i].y;
						D[y]--;
						g[y]=max(g[y],a[xx]+1);
						if (D[y]==0)
							Q1.push(make_pair(g[y],y));
					}
					break;
				}
			}
		/*	for (int i=1;i<=n;i++) printf("%d ",a[i]);
			printf("\n");
			system("pause");*/
			if (tt[u]==0) {printf("-1");return ;}
		}
	for (int u=1;u<=n;u++) printf("%d ",a[u]);
}
queue<int> q;
void solve ()
{
	int tot=0;
	for (int u=1;u<=n;u++)
		if (d[u]==0)
		{
			q.push(u);
			if (o[u]==false) a[u]=k;
		}
/*	for (int u=1;u<=n;u++) printf("%d ",a[u]);
		printf("\n");*/
	while (!q.empty())
	{
		tot++;int x=q.front();
		for (int u=last[x];u!=-1;u=e[u].last)
		{
			int y=e[u].y;
			if (o[y])
			{
				if (a[y]>=a[x])
				{
					printf("-1");
					return ;
				}
			}
			else	a[y]=min(a[y],a[x]-1);
			d[y]--;
			if (d[y]==0)	q.push(y);
		}
		//printf("%d\n",x);
		q.pop();/*
		*/
	}
	for (int u=1;u<=n;u++)
		if (a[u]<=0)
		{
			printf("-1");
			return ;
		}

	if (tot!=n)
	{
		printf("-1");
		return ;
	}/*for (int u=1;u<=n;u++) printf("%d ",a[u]);
		printf("\n");*/
	solve1();
}
int main()
{
	num=0;memset(last,-1,sizeof(last));
	memset(Last,-1,sizeof(Last));
	scanf("%d%d%d",&n,&m,&k);
	for (int u=1;u<=n;u++)
	{
		scanf("%d",&a[u]);
		if (a[u]==0)
		{
			a[u]=k+1;
			o[u]=false;
		}
		else o[u]=true;
	}
	for (int u=1;u<=m;u++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		init(x,y);
	}
	solve();
	return 0;
}


#include<cstdio>
#include<queue>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
typedef pair<int,int> PI;
const int N=200005;
int n,m,k;
int a[N];
bool o[N];//是不是一开始有有数了
struct qq
{
	int x,y,last;
}e[N];int num,last[N];
qq E[N];int Last[N];
int d[N],D[N];
void init (int x,int y)
{
	num++;d[y]++;
	e[num].x=x;e[num].y=y;
	e[num].last=last[x];
	last[x]=num;

	swap(x,y);
	D[y]++;
	E[num].x=x;E[num].y=y;
	E[num].last=Last[x];
	Last[x]=num;
}
priority_queue<PI,vector<PI>,greater<PI> >Q;
int tt[N];
int g[N];
void solve1 ()
{
	memset(g,0,sizeof(g));
	for (int u=1;u<=n;u++)
	{
		if (D[u]==0)
		{
			Q.push(make_pair(1,u));
			g[u]=1;
		}
		tt[a[u]]++;
	}
	for (int u=1;u<=k;u++)
		if (tt[u]==0)//如果这个颜色不存在
		{
			while (!Q.empty())
			{
				int x=Q.top().first,xx=Q.top().second;Q.pop();
				if (x>u) break;
				if (a[xx]<u||o[xx])
				{
					for (int i=Last[xx];i!=-1;i=E[i].last)
					{
						int y=E[i].y;
						D[y]--;
						g[y]=max(g[y],a[xx]+1);
						if (D[y]==0)
							Q.push(make_pair(g[y],y));
					}
					continue;
				}
				else
				{
					tt[a[xx]]--;
					a[xx]=u;
					tt[u]++;
					for (int i=Last[xx];i!=-1;i=E[i].last)
					{
						int y=E[i].y;
						D[y]--;
						g[y]=max(g[y],a[xx]+1);
						if (D[y]==0)
							Q.push(make_pair(g[y],y));
					}
					break;
				}
			}
			if (tt[u]==0) {printf("-1");return ;}
		}
	for (int u=1;u<=n;u++) printf("%d ",a[u]);
}
queue<int> q;
void solve ()
{
	int tot=0;
	for (int u=1;u<=n;u++)
		if (d[u]==0)
		{
			q.push(u);
			if (o[u]==false) a[u]=k;
		}

	while (!q.empty())
	{
		tot++;int x=q.front();
		for (int u=last[x];u!=-1;u=e[u].last)
		{
			int y=e[u].y;
			if (o[y])
			{
				if (a[y]>=a[x])
				{
					printf("-1");
					return ;
				}
			}
			else	a[y]=min(a[y],a[x]-1);
			d[y]--;
			if (d[y]==0)	q.push(y);
		}
		q.pop();
	}
	for (int u=1;u<=n;u++)
		if (a[u]<=0)
		{
			printf("-1");
			return ;
		}
	if (tot!=n)
	{
		printf("-1");
		return ;
	}
	solve1();
}
int main()
{
	num=0;memset(last,-1,sizeof(last));
	memset(Last,-1,sizeof(Last));
	scanf("%d%d%d",&n,&m,&k);
	for (int u=1;u<=n;u++)
	{
		scanf("%d",&a[u]);
		if (a[u]==0)
		{
			a[u]=k+1;
			o[u]=false;
		}
		else o[u]=true;
	}
	for (int u=1;u<=m;u++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		init(x,y);
	}
	solve();
	return 0;
}


#include<bits/stdc++.h>
#define LL long long
#define ull unsigned long long
#define ULL ull
#define mp make_pair
#define pii pair<int,int>
#define piii pair<int, pii >
#define pll pair <ll,ll>
#define pb push_back
#define big 20160116
#define INF 2147483647
#define pq priority_queue
#define rank rk124232
#define y1 y20160116
#define y0 y20160110
using namespace std;
inline int read(){
	int x=0,f=1;
	char ch=getchar();
	while (ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
	while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
namespace Mymath{
	LL qp(LL x,LL p,LL mod){
		LL ans=1;
		while (p){
			if (p&1) ans=ans*x%mod;
			x=x*x%mod;
			p>>=1;
		}
		return ans;
	}
	LL inv(LL x,LL mod){
		return qp(x,mod-2,mod);
	}
	LL C(LL N,LL K,LL fact[],LL mod){
		return fact[N]*inv(fact[K],mod)%mod*inv(fact[N-K],mod)%mod;
	}
	template <typename Tp> Tp gcd(Tp A,Tp B){
		if (B==0) return A;
		return gcd(B,A%B);
	}
	template <typename Tp> Tp lcm(Tp A,Tp B){
		return A*B/gcd(A,B);
	}
};
namespace fwt{
	using namespace Mymath;
	void FWT(int a[],int n,LL mod)
	{
	    for(int d=1;d<n;d<<=1)
	        for(int m=d<<1,i=0;i<n;i+=m)
	            for(int j=0;j<d;j++)
	            {
	                int x=a[i+j],y=a[i+j+d];
	                a[i+j]=(x+y)%mod,a[i+j+d]=(x-y+mod)%mod;
	                //xor:a[i+j]=x+y,a[i+j+d]=x-y;
	                //and:a[i+j]=x+y;
	                //or:a[i+j+d]=x+y;
	            }
	}

	void UFWT(int a[],int n,LL mod)
	{
		LL rev=inv(2,mod);
	    for(int d=1;d<n;d<<=1)
	        for(int m=d<<1,i=0;i<n;i+=m)
	            for(int j=0;j<d;j++)
	            {
	                int x=a[i+j],y=a[i+j+d];
	                a[i+j]=1LL*(x+y)*rev%mod,a[i+j+d]=(1LL*(x-y)*rev%mod+mod)%mod;
	                //xor:a[i+j]=(x+y)/2,a[i+j+d]=(x-y)/2;
	                //and:a[i+j]=x-y;
	                //or:a[i+j+d]=y-x;
	            }
	}
	void solve(int a[],int b[],int n,LL mod)
	{
	    FWT(a,n,mod);
	    FWT(b,n,mod);
	    for(int i=0;i<n;i++) a[i]=1LL*a[i]*b[i]%mod;
	    UFWT(a,n,mod);
	}
};
const int Maxn=2e5+5;
int n,m,k;
vector<int> G[Maxn],Gr[Maxn];
int r[Maxn];
int lo[Maxn],hi[Maxn];
int ord[Maxn];
vector<pair<int,int> > R[Maxn];
int ans[Maxn];
bool hav[Maxn];
int deg[Maxn];
int main(){
	n=read();m=read();k=read();
	for (int i=1;i<=n;i++){
		r[i]=read();
		if (r[i]) lo[i]=hi[i]=r[i],hav[r[i]]=true;
		else{
			lo[i]=1;
			hi[i]=k;
		}
	}
	for (int i=0;i<m;i++){
		int u,v;
		u=read();v=read();G[u].pb(v);
		Gr[v].pb(u);
		deg[v]++;
	}
	int co=0;
	vector<int> V;
	for (int i=1;i<=n;i++){
		if (!deg[i]){
			V.pb(i);
		}
	}
	while (!V.empty()){
		int x=V.back();V.pop_back();
		ord[++co]=x;
		for (int i=0;i<G[x].size();i++){
			int v=G[x][i];
			deg[v]--;
			if (!deg[v]){
				V.pb(v);
			}
		}
	}
	if (co!=n){
		puts("-1");
		return 0;
	}
	//cerr<<123<<endl;
	for (int i=n;i>=1;i--){
		int v=ord[i];
		for (int j=0;j<G[v].size();j++){
			lo[v]=max(lo[v],lo[G[v][j]]+1);
		}
	}
	for (int i=1;i<=n;i++){
		int v=ord[i];
		for (int j=0;j<Gr[v].size();j++){
			hi[v]=min(hi[v],hi[Gr[v][j]]-1);
		}
	}
	//cerr<<213<<endl;
	for (int i=1;i<=n;i++){
	//	cout<<i<<' '<<lo[i]<<' '<<hi[i]<<endl;
		if (lo[i]>hi[i]){
			puts("-1");return 0;
		}
		R[lo[i]].pb(mp(-hi[i],i));
	}
	priority_queue<pair<int,int> > Q;
	//cerr<<123<<endl;
	for (int i=1;i<=k;i++){
		for (int j=0;j<R[i].size();j++){
			Q.push(R[i][j]);
		}
		if (hav[i]){
			//cout<<i<<endl;
			while (!Q.empty() && Q.top().first==-i){
				ans[Q.top().second]=i;
				//cout<<i<<' '<<Q.top().second<<endl;
				Q.pop();
			}
		}
		else{
			if (Q.empty()){
				puts("-1");
				return 0;
			}
			pii tmp=Q.top();
			ans[tmp.second]=i;
			//cout<<tmp.second<<' '<<i<<endl;
			Q.pop();
			while (!Q.empty() && Q.top().first==-i){
				ans[Q.top().second]=i;
				Q.pop();
			}
		}
	}
	for (int i=1;i<=n;i++){
		printf("%d ",ans[i]);
	}
	puts("");
	return 0;
}


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

using namespace std;
#define MAXN 200000
#define pb push_back
#define Trav(s) for(rint i = 0, _sz = (int)s.size(), v; i < _sz; i++)
#define rint register int
#define gc() getchar()
inline int read(rint ans = 0, rint sgn = ' ', rint ch = gc())
{
	for(; ch < '0' || ch > '9'; sgn = ch, ch = gc());
	for(; ch >='0' && ch <='9';(ans*=10)+=ch-'0', ch = gc());
	return sgn-'-'?ans:-ans;
}
#define BUF_SIZE 1000000
#define _END fwrite(_Ob,1,_O-_Ob,stdout), _O = _Ob
#define Outc(a) (*_O++ = a)
char _Ob[BUF_SIZE+5], *_O = _Ob, _Os[25], *_Ot;
template <typename T> inline void Out(T x)
{
	if(!x){Outc('0'); return;} if(x < 0) Outc('-'), x = -x;
	for(_Ot = _Os; x; *_Ot++ = x%10+'0', x /= 10);
	for(; _Ot != _Os; Outc(*--_Ot)); if(_O-_Ob >= BUF_SIZE-50) _END;
}
int n, m, k, r[MAXN+5], ub[MAXN+5], lb[MAXN+5], d[MAXN+5], q[MAXN+5], c[MAXN+5], head, tail;
vector<int> e[MAXN+5], g[MAXN+5], f[MAXN+5]; vector<int>::iterator it;
struct D{int i; D(){} D(int _i):i(_i){}}; inline bool operator > (D i, D j){return ub[i.i]>ub[j.i];} priority_queue<D,vector<D>,greater<D> > T;
inline int Release(int p, int t){r[p] = t; Trav(g[p]) v = g[p][i], lb[v] = max(lb[v],r[p]+1), !--c[v] ? f[lb[v]].pb(v),0 : 0;}
int main()
{
	n = read(), m = read(), k = read();
	for(rint i = 1; i <= n; r[i] = read(), ub[i] = r[i] ?: k, lb[i] = r[i] ?: 1, i++);
	for(rint u, v; m--; u = read(), v = read(), e[u].pb(v), g[v].pb(u), ++c[u], ++d[v]);
	for(rint i = 1; i <= n; d[i] ?: q[++tail] = i, i++);
	for(rint p; head <= tail; ) Trav(e[p=q[head++]]) !--d[v=e[p][i]] ? q[++tail] = v : 0; if(tail < n){puts("-1"); return 0;}
	for(rint j = 1, p, i, _sz, v; j <= n; j++) Trav(e[p=q[j]]) v = e[p][i], ub[v] = min(ub[v],ub[p]-1);
	for(rint i = 1; i <= n; i++) if(lb[i] > ub[i]){puts("-1"); return 0;}
	for(rint i = 1; i <= n; c[i] ?: (f[lb[i]].pb(i),0), i++);
	for(rint j = 1, p, i, _sz, v; j <= k; j++)
	{
		for(it = f[j].begin(); it != f[j].end(); T.push(D(*it)), it++); if(T.empty()){puts("-1"); return 0;}
		for(Release(T.top().i,j), T.pop(); !T.empty() && ub[p=T.top().i] == j; Release(p,j), T.pop());
	}	for(rint i = 1; i <= n; printf("%d ",r[i]), i++); return 0;
}


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

using namespace std;
#define MAXN 200000
#define pb push_back
#define Trav(s) for(rint i = 0, _sz = (int)s.size(), v; i < _sz; i++)
#define rint register int
#define gc() getchar()
inline int read(rint ans = 0, rint sgn = ' ', rint ch = gc())
{
	for(; ch < '0' || ch > '9'; sgn = ch, ch = gc());
	for(; ch >='0' && ch <='9';(ans*=10)+=ch-'0', ch = gc());
	return sgn-'-'?ans:-ans;
}
#define BUF_SIZE 1000000
#define _END fwrite(_Ob,1,_O-_Ob,stdout), _O = _Ob
#define Outc(a) (*_O++ = a)
char _Ob[BUF_SIZE+5], *_O = _Ob, _Os[25], *_Ot;
template <typename T> inline void Out(T x)
{
	if(!x){Outc('0'); return;} if(x < 0) Outc('-'), x = -x;
	for(_Ot = _Os; x; *_Ot++ = x%10+'0', x /= 10);
	for(; _Ot != _Os; Outc(*--_Ot)); if(_O-_Ob >= BUF_SIZE-50) _END;
}
int n, m, k, r[MAXN+5], ub[MAXN+5], lb[MAXN+5], d[MAXN+5], q[MAXN+5], c[MAXN+5], head, tail;
vector<int> e[MAXN+5], g[MAXN+5], f[MAXN+5]; vector<int>::iterator it;
struct D{int i; D(){} D(int _i):i(_i){}}; inline bool operator > (D i, D j){return ub[i.i]>ub[j.i];} priority_queue<D,vector<D>,greater<D> > T;
inline int Release(int p, int t){r[p] = t; Trav(g[p]) v = g[p][i], lb[v] = max(lb[v],r[p]+1), !--c[v] ? f[lb[v]].pb(v),0 : 0;}
int main()
{
	n = read(), m = read(), k = read();
	for(rint i = 1; i <= n; r[i] = read(), ub[i] = r[i] ?: k, lb[i] = r[i] ?: 1, i++);
	for(rint u, v; m--; u = read(), v = read(), e[u].pb(v), g[v].pb(u), ++c[u], ++d[v]);
	for(rint i = 1; i <= n; d[i] ?: q[++tail] = i, i++);
	for(rint p; head <= tail; ) Trav(e[p=q[head++]]) !--d[v=e[p][i]] ? q[++tail] = v : 0;
	if(tail < n){puts("-1"); return 0;} for(rint i = 1; i <= n; i++) if(lb[i] > ub[i]){puts("-1"); return 0;}
	for(rint j = 1, p, i, _sz, v; j <= n; j++) Trav(e[p=q[j]]) v = e[p][i], ub[v] = min(ub[v],ub[p]-1);
	for(rint i = 1; i <= n; c[i] ?: (f[lb[i]].pb(i),0), i++);
	for(rint j = 1, p, i, _sz, v; j <= k; j++)
	{
		for(it = f[j].begin(); it != f[j].end(); T.push(D(*it)), it++); if(T.empty()){puts("-1"); return 0;}
		for(Release(T.top().i,j), T.pop(); !T.empty() && ub[p=T.top().i] == j; Release(p,j), T.pop());
	}	for(rint i = 1; i <= n; printf("%d ",r[i]), i++); return 0;
}


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

using namespace std;
#define MAXN 200000
#define pb push_back
#define Trav(s) for(rint i = 0, _sz = (int)s.size(), v; i < _sz; i++)
#define rint register int
#define gc() getchar()
inline int read(rint ans = 0, rint sgn = ' ', rint ch = gc())
{
	for(; ch < '0' || ch > '9'; sgn = ch, ch = gc());
	for(; ch >='0' && ch <='9';(ans*=10)+=ch-'0', ch = gc());
	return sgn-'-'?ans:-ans;
}
#define BUF_SIZE 1000000
#define _END fwrite(_Ob,1,_O-_Ob,stdout), _O = _Ob
#define Outc(a) (*_O++ = a)
char _Ob[BUF_SIZE+5], *_O = _Ob, _Os[25], *_Ot;
template <typename T> inline void Out(T x)
{
	if(!x){Outc('0'); return;} if(x < 0) Outc('-'), x = -x;
	for(_Ot = _Os; x; *_Ot++ = x%10+'0', x /= 10);
	for(; _Ot != _Os; Outc(*--_Ot)); if(_O-_Ob >= BUF_SIZE-50) _END;
}
int n, m, k, r[MAXN+5], ub[MAXN+5], lb[MAXN+5], d[MAXN+5], q[MAXN+5], c[MAXN+5], head, tail;
vector<int> e[MAXN+5], g[MAXN+5], f[MAXN+5]; vector<int>::iterator it;
struct D{int i; D(){} D(int _i):i(_i){}}; inline bool operator > (D i, D j){return ub[i.i]>ub[j.i];}
priority_queue<D,vector<D>,greater<D> > T;
inline int Release(int p, int t)
{r[p] = t; Trav(g[p]) v = g[p][i], lb[v] = max(lb[v],r[p]+1), !--c[v] ? f[lb[v]].pb(v),0 : 0;}
int main()
{
	n = read(), m = read(), k = read();
	for(rint i = 1; i <= n; r[i] = read(), ub[i] = r[i] ?: k, lb[i] = r[i] ?: 1, i++);
	for(rint u, v; m--; u = read(), v = read(), e[u].pb(v), g[v].pb(u), ++c[u], ++d[v]);
	for(rint i = 1; i <= n; d[i] ?: q[++tail] = i, i++);
	for(rint p; head <= tail; ) Trav(e[p=q[head++]]) !--d[v=e[p][i]] ? q[++tail] = v : 0;
	if(tail < n){puts("-1"); return 0;} for(rint i = 1; i <= n; i++) if(lb[i] > ub[i]){puts("-1"); return 0;}
	for(rint i = 1; i <= n; c[i] ?: (f[lb[i]].pb(i),0), i++);
	for(rint j = 1, p, i, _sz, v; j <= k; j++)
	{
		for(it = f[j].begin(); it != f[j].end(); T.push(D(*it)), it++); if(T.empty()){puts("-1"); return 0;}
		for(Release(T.top().i,j), T.pop(); !T.empty() && ub[p=T.top().i] == j; Release(p,j), T.pop());
	}	for(rint i = 1; i <= n; printf("%d ",r[i]), i++); return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>

using namespace std;
#define MAXN 1000
#define MAXM 20000
#define INF 1000000001
#define Trav(p) for(rint i = 0, _sz = (int)e[p].size(), v; i < _sz; i++)
#define pb push_back
#define rint register int
#define gc() getchar()
inline int read(rint ans = 0, rint sgn = ' ', rint ch = gc())
{
	for(; ch < '0' || ch > '9'; sgn = ch, ch = gc());
	for(; ch >='0' && ch <='9';(ans*=10)+=ch-'0', ch = gc());
	return sgn-'-'?ans:-ans;
}
#define BUF_SIZE 1000000
#define _END fwrite(_Ob,1,_O-_Ob,stdout), _O = _Ob
#define Outc(a) (*_O++ = a)
char _Ob[BUF_SIZE+5], *_O = _Ob, _Os[25], *_Ot;
template <typename T> inline void Out(T x)
{
	if(!x){Outc('0'); return;} if(x < 0) Outc('-'), x = -x;
	for(_Ot = _Os; x; *_Ot++ = x%10+'0', x /= 10);
	for(; _Ot != _Os; Outc(*--_Ot)); if(_O-_Ob >= BUF_SIZE-50) _END;
}
struct Edge{int u,v,x,w; Edge(){} Edge(int _u, int _v, int _w):u(_u),v(_v),x(_u^_v),w(_w){}}ed[MAXM+5];
struct D{int s,d; D(){} D(int _s, int _d):s(_s),d(_d){}}q[MAXM+5], tmp; vector<int> e[MAXN+5];
inline bool operator < (D a, D b){return a.d > b.d;}
int dis[MAXN+5], n, m, p, L, S, T, sz, lef, rig, mid, res, r;
void Dijkstra()
{
	memset(dis+1,0x3f,n<<2), dis[S] = 0, q[1] = D(S,dis[S]), sz = 1;
	for(rint p; sz; )
	{
		tmp = q[1], pop_heap(q+1,q+sz--+1); if(dis[p=tmp.s] < tmp.d) continue;
		Trav(p) if(ed[e[p][i]].w < INF && dis[v=p^ed[e[p][i]].x] > dis[p]+ed[e[p][i]].w)
			dis[v] = dis[p]+ed[e[p][i]].w, q[++sz] = D(v,dis[v]), make_heap(q+1,q+sz+1);
	}
}
inline bool Check(int K){for(rint i = p+1; i <= m; ed[i].w = i<=K?INF:0, i++); return Dijkstra(), dis[T] <= L;}
inline bool Check2(int K){ed[r].w = K; return Dijkstra(), dis[T] <= L;}
int main()
{
	n = read(), m = read(), p = 0, L = read(), S = read()+1, T = read()+1;
	for(rint i = 1, u, v; i <= m; u = read()+1, v = read()+1, ed[i] = Edge(u,v,read()), ed[i].w ? swap(ed[i],ed[++p]),0 : 0, i++); for(rint i = 1; i <= m; e[ed[i].u].pb(i), e[ed[i].v].pb(i), i++);
	if(p == m){if(Dijkstra(), dis[T] == L){puts("YES"); for(rint i = 1; i <= m; printf("%d %d %d\n",ed[i].u-1,ed[i].v-1,ed[i].w), i++);} else puts("NO"); return 0;}
	for(res = lef = p, rig = m; lef <= rig; Check(mid=lef+rig>>1) ? res = mid, lef = mid+1 : rig = mid-1); if((res >= m && (Check(m), dis[T] < L)) || (res <= p && !Check(res))){puts("NO"); return 0;}
	r = res; for(rint i = p+1; i <= m; ed[i].w = i<=r?INF:0, i++); ++r; for(lef = 0, rig = L; lef <= rig; Check2(mid=lef+rig>>1) ? res = mid , lef = mid+1 : rig = mid-1); ed[r].w = res;
	puts("YES"); for(rint i = 1; i <= m; printf("%d %d %d\n",ed[i].u-1,ed[i].v-1,ed[i].w), i++); return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int MAXN=210000;
int n,m,k;
vector<int> head[MAXN];
vector<pair<int, int> > rnk[MAXN];
int solid[MAXN];
int low[MAXN],ans[MAXN];
int high[MAXN];
int in[MAXN];
int flag=1;
struct Edge
{
    int x,y;
    Edge() {}
}edge[MAXN];
void Input()
{
    scanf("%d%d%d",&n,&m,&k);
    for(int i=1;i<=n;++i)
    {
        scanf("%d",&solid[i]);
    }
    int u,v;
    for(int i=1;i<=m;++i)
    {
        scanf("%d%d",&edge[i].x,&edge[i].y);
    }
}
void init()
{
    for(int i=1;i<=n;++i)
    {
        head[i].clear();
        in[i]=0;
    }
}
void toposort(int now[],int type)
{
    queue<int > q;
    int cnt=0;
    for(int i=1;i<=n;++i)
    {
        if(!in[i])
        {
            q.push(i);
            ++cnt;
        }
    }
    while(!q.empty())
    {
        int u=q.front();q.pop();
        for(int i=0;i<head[u].size();++i)
        {
            int v=head[u][i];
            if(type<0)
            {
                now[v]=min(now[v],now[u]-1);
            }
            else
            {
                now[v]=max(now[u],now[v]+1);
            }
            if(--in[v]<=0)
            {
                ++cnt;
                q.push(v);
            }
        }
    }
    if(cnt!=n)
    {
        flag=0;
    }
}
void work()
{
    int u,v;
    flag=1;
    init();
    for(int i=1;i<=n;++i)
    {
        if(solid[i]) high[i]=solid[i];
        else high[i]=k;
    }
    for(int i=1;i<=m;++i)
    {
        u=edge[i].x,v=edge[i].y;
        head[u].push_back(v);
        in[v]++;
    }
    toposort(high,-1);
    if(flag==0)
    {
        printf("-1\n");
        return;
    }
    init();
    for(int i=1;i<=n;++i)
    {
        if(solid[i]) low[i]=solid[i];
        else low[i]=1;
    }
    for(int i=1;i<=m;++i)
    {
        u=edge[i].y;v=edge[i].x;
        head[u].push_back(v);
        in[v]++;
    }
    toposort(low,1);
    if(flag==0)
    {
        printf("-1\n");
        return;
    }

    for(int i=1;i<=n;++i)
    {
        if(low[i]>high[i])
        {
            printf("-1\n");return;
        }
    }
    int top=k;
    for(int i=1;i<=k;++i) rnk[i].clear();
    for(int i=1;i<=n;++i)
    {
        rnk[high[i]].push_back(make_pair(-low[i],i));
    }
    set< pair<int,int> > S;
    set< pair<int,int> >::iterator it;
    for(int i=0;i<rnk[k].size();++i)
    {
        S.insert(rnk[k][i]);
    }
    pair<int ,int > tmp;
    while(top)
    {
        if(S.empty())
        {
            printf("-1\n");
            return;
        }
        it=S.begin();
        tmp=*it;
        ans[tmp.second]=top;
        S.erase(it);
        while(1)
        {
            it=S.begin();
            tmp=*it;
            if(-tmp.first<top) break;
            ans[tmp.second]=top;
            S.erase(it);
        }
        --top;
        for(int i=0;i<rnk[top].size();++i)
        {
            S.insert(rnk[top][i]);
        }
    }
    while(!S.empty())
    {
        tmp=*it;
        ans[tmp.second]=1;
        S.erase(it);
    }
    for(int i=1;i<=n;++i)
        printf("%d ",ans[i]);
    printf("\n");
}
int main()
{
    Input();
    work();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int MAXN=210000;
int n,m,k;
vector<int> head[MAXN];
vector<pair<int, int> > rnk[MAXN];
int solid[MAXN];
int low[MAXN],ans[MAXN];
int high[MAXN];
int in[MAXN];
int flag=1;
struct Edge
{
    int x,y;
    Edge() {}
}edge[MAXN];
void Input()
{
    scanf("%d%d%d",&n,&m,&k);
    for(int i=1;i<=n;++i)
    {
        scanf("%d",&solid[i]);
    }
    int u,v;
    for(int i=1;i<=m;++i)
    {
        scanf("%d%d",&edge[i].x,&edge[i].y);
    }
}
void init()
{
    for(int i=1;i<=n;++i)
    {
        head[i].clear();
        in[i]=0;
    }
}
void toposort(int now[],int type)
{
    queue<int > q;
    int cnt=0;
    for(int i=1;i<=n;++i)
    {
        if(!in[i])
        {
            q.push(i);
            ++cnt;
        }
    }
    while(!q.empty())
    {
        int u=q.front();q.pop();
        for(int i=0;i<head[u].size();++i)
        {
            int v=head[u][i];
            if(type<0)
            {
                now[v]=min(now[v],now[u]-1);
            }
            else
            {
                now[v]=max(now[v],now[u]+1);
            }
            if(--in[v]<=0)
            {
                ++cnt;
                q.push(v);
            }
        }
    }
    if(cnt!=n)
    {
        flag=0;
    }
}
void work()
{
    int u,v;
    flag=1;
    init();
    for(int i=1;i<=n;++i)
    {
        if(solid[i]) high[i]=solid[i];
        else high[i]=k;
    }
    for(int i=1;i<=m;++i)
    {
        u=edge[i].x,v=edge[i].y;
        head[u].push_back(v);
        in[v]++;
    }
    toposort(high,-1);
    if(flag==0)
    {
        printf("-1\n");
        return;
    }
    init();
    for(int i=1;i<=n;++i)
    {
        if(solid[i]) low[i]=solid[i];
        else low[i]=1;
    }
    for(int i=1;i<=m;++i)
    {
        u=edge[i].y;v=edge[i].x;
        head[u].push_back(v);
        in[v]++;
    }
    toposort(low,1);
    if(flag==0)
    {
        printf("-1\n");
        return;
    }

    for(int i=1;i<=n;++i)
    {
        if(low[i]>high[i])
        {
            printf("-1\n");return;
        }
    }
    int top=k;
    for(int i=1;i<=k;++i) rnk[i].clear();
    for(int i=1;i<=n;++i)
    {
        rnk[high[i]].push_back(make_pair(-low[i],i));
    }
    set< pair<int,int> > S;
    set< pair<int,int> >::iterator it;
    for(int i=0;i<rnk[k].size();++i)
    {
        S.insert(rnk[k][i]);
    }
    pair<int ,int > tmp;
    while(top)
    {
        if(S.empty())
        {
            printf("-1\n");
            return;
        }
        it=S.begin();
        tmp=*it;
        ans[tmp.second]=top;
        S.erase(it);
        while(1)
        {
            it=S.begin();
            tmp=*it;
            if(-tmp.first<top) break;
            ans[tmp.second]=top;
            S.erase(it);
        }
        --top;
        for(int i=0;i<rnk[top].size();++i)
        {
            S.insert(rnk[top][i]);
        }
    }
    while(!S.empty())
    {
        tmp=*it;
        ans[tmp.second]=1;
        S.erase(it);
    }
    for(int i=1;i<=n;++i)
        printf("%d ",ans[i]);
    printf("\n");
}
int main()
{
  //  freopen("in.txt","r",stdin);
    Input();
    work();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int MAXN=210000;
int n,m,k;
vector<int> head[MAXN];
vector<pair<int, int> > rnk[MAXN];
int solid[MAXN];
int low[MAXN],ans[MAXN];
int high[MAXN];
int in[MAXN];
int flag=1;
struct Edge
{
    int x,y;
    Edge() {}
}edge[MAXN];
void Input()
{
    scanf("%d%d%d",&n,&m,&k);
    for(int i=1;i<=n;++i)
    {
        scanf("%d",&solid[i]);
    }
    int u,v;
    for(int i=1;i<=m;++i)
    {
        scanf("%d%d",&edge[i].x,&edge[i].y);
    }
}
void init()
{
    for(int i=1;i<=n;++i)
    {
        head[i].clear();
        in[i]=0;
    }
}
void toposort(int now[],int type)
{
    queue<int > q;
    int cnt=0;
    for(int i=1;i<=n;++i)
    {
        if(!in[i])
        {
            q.push(i);
            ++cnt;
        }
    }
    while(!q.empty())
    {
        int u=q.front();q.pop();
        for(int i=0;i<head[u].size();++i)
        {
            int v=head[u][i];
            if(type<0)
            {
                if(!solid[v]) now[v]=min(now[v],now[u]-1);
            }
            else
            {
                if(!solid[v]) now[v]=max(now[v],now[u]+1);
            }
            if(--in[v]<=0)
            {
                ++cnt;
                q.push(v);
            }
        }
    }
    if(cnt!=n)
    {
        flag=0;
    }
}
void work()
{
    int u,v;
    flag=1;
    init();
    for(int i=1;i<=n;++i)
    {
        if(solid[i]) high[i]=solid[i];
        else high[i]=k;
    }
    for(int i=1;i<=m;++i)
    {
        u=edge[i].x,v=edge[i].y;
        head[u].push_back(v);
        in[v]++;
    }
    toposort(high,-1);
    if(flag==0)
    {
        printf("-1\n");
        return;
    }
    init();
    for(int i=1;i<=n;++i)
    {
        if(solid[i]) low[i]=solid[i];
        else low[i]=1;
    }
    for(int i=1;i<=m;++i)
    {
        u=edge[i].y;v=edge[i].x;
        head[u].push_back(v);
        in[v]++;
    }
    toposort(low,1);
    if(flag==0)
    {
        printf("-1\n");
        return;
    }

    for(int i=1;i<=n;++i)
    {
        if(low[i]>high[i])
        {
            printf("-1\n");return;
        }
    }
    int top=k;
    for(int i=1;i<=k;++i) rnk[i].clear();
    for(int i=1;i<=n;++i)
    {
        rnk[high[i]].push_back(make_pair(-low[i],i));
    }
    set< pair<int,int> > S;
    set< pair<int,int> >::iterator it;
    for(int i=0;i<rnk[k].size();++i)
    {
        S.insert(rnk[k][i]);
    }
    pair<int ,int > tmp;
    while(top)
    {
        if(S.empty())
        {
            printf("-1\n");
            return;
        }
        it=S.begin();
        tmp=*it;
        ans[tmp.second]=top;
        S.erase(it);
        while(1)
        {
            it=S.begin();
            tmp=*it;
            if(-tmp.first<top) break;
            ans[tmp.second]=top;
            S.erase(it);
        }
        --top;
        for(int i=0;i<rnk[top].size();++i)
        {
            S.insert(rnk[top][i]);
        }
    }
    while(!S.empty())
    {
        tmp=*it;
        ans[tmp.second]=1;
        S.erase(it);
    }
    for(int i=1;i<=n;++i)
        printf("%d ",ans[i]);
    printf("\n");
}
int main()
{
  //  freopen("in.txt","r",stdin);
    Input();
    work();
    return 0;
}


#include <cstdio>
#include <cstring>
#include <utility>
#include <queue>
#include <vector>
#define mp(A,B) make_pair(A,B)
using namespace std;
const int maxn=200010;
typedef pair<int,int> pii;
int n,m,k,cnt,flag;
int to[maxn],nxt[maxn],head[maxn],pa[maxn],pb[maxn],v[maxn],L[maxn],R[maxn],d[maxn],ans[maxn];
vector<int> p[maxn];
vector<int>::iterator it;
queue<int> q;
priority_queue<pii> pq;
inline int rd()
{
    int ret=0,f=1;  char gc=getchar();
    while(gc<'0'||gc>'9') {if(gc=='-')    f=-f;   gc=getchar();}
    while(gc>='0'&&gc<='9')   ret=ret*10+(gc^'0'),gc=getchar();
    return ret*f;
}
inline void add(int a,int b)
{
    to[cnt]=b,nxt[cnt]=head[a],head[a]=cnt++;
}
int main()
{
    n=rd(),m=rd(),k=rd();
    int i,u;
    for(i=1;i<=n;i++)
    {
        v[i]=rd();
        if(!v[i])   L[i]=1,R[i]=k;
        else    L[i]=R[i]=v[i];
    }
    memset(head,-1,sizeof(head)),cnt=0;
    for(i=1;i<=m;i++)    pa[i]=rd(),pb[i]=rd(),d[pb[i]]++,add(pa[i],pb[i]);
    for(i=1;i<=n;i++)    if(!d[i])   q.push(i);
    while(!q.empty())
    {
        u=q.front(),q.pop();
        for(i=head[u];i!=-1;i=nxt[i])
        {
            d[to[i]]--,R[to[i]]=min(R[to[i]],R[u]-1);
            if(!d[to[i]])   q.push(to[i]);
        }
    }
    for(i=1;i<=n;i++)    if(d[i])    return puts("-1"),0;
    memset(head,-1,sizeof(head)),cnt=0;
    for(i=1;i<=m;i++)    d[pa[i]]++,add(pb[i],pa[i]);
    for(i=1;i<=n;i++)    if(!d[i])   q.push(i);
    while(!q.empty())
    {
        u=q.front(),q.pop();
        for(i=head[u];i!=-1;i=nxt[i])
        {
            d[to[i]]--,L[to[i]]=max(L[to[i]],L[u]+1);
            if(!d[to[i]])   q.push(to[i]);
        }
    }
    for(i=1;i<=n;i++)    if(d[i]||L[i]>R[i])  return puts("-1"),0;
    for(i=1;i<=n;i++)    p[R[i]].push_back(i);
    for(i=k;i>=1;i--)
    {
        for(it=p[i].begin();it!=p[i].end();it++)    pq.push(mp(L[*it],*it));
        if(pq.empty())  return puts("-1"),0;
        u=pq.top().second,pq.pop(),ans[u]=i;
        while(!pq.empty())
        {
            u=pq.top().second;
            if(L[u]<i)   break;
            pq.pop(),ans[u]=i;
        }
    }
    for(i=1;i<=n;i++)    printf("%d ",ans[i]);
    return 0;
}


#include<ctime>
#include<algorithm>
#include<cstdio>
#include<set>
#include<memory.h>
#include<queue>
#include<cmath>
using namespace std;
#define ll int
#define For(i,x,y)  for(int i=x;i<=y;++i)
#define FOr(i,x,y)  for(int i=x;i>=y;--i)
inline ll read(){  ll x=0,f=0; char ch=getchar();  while(ch<'0'||ch>'9'){ if(ch=='-') f=1; ch=getchar(); }   while(ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0', ch=getchar(); return f?-x:x;}
void write(ll x){   if (x<0) x=-x,putchar('-');  if (x>=10)   write(x/10);    putchar(x%10+'0');}
inline void writeln(ll x)  {   write(x);   puts("");   }
const ll N=400010;	bool vis[N];
ll head[N],nxt[N],vet[N],ned[N],dis[N],dfn[N],n,m,k,tot,he,ta;	pair<ll,ll>q[N];
void insert(ll x,ll y){	nxt[++tot]=head[x];	head[x]=tot;	vet[tot]=y;	++dfn[x];	}
int main(){
//	freopen("a.in","r",stdin);
	n=read();	m=read();	k=read();
	For(i,1,n){
		dis[i]=read();
		if (dis[i])	q[++ta]=make_pair(dis[i],i),ned[i]=1;
	}
	For(i,1,m){
		ll x=read(),y=read();
		insert(y,x);
	}
	For(i,1,n)	if (dfn[i]&&!dis[i])	q[++ta]=make_pair(dis[i]=1,i);
	while(he!=ta){
		ll x=q[he=he%n+1].second;
		for(ll i=head[x];i;i=nxt[i])
		if (dis[vet[i]]<dis[x]+1){
			if (ned[vet[i]])	return puts("-1"),0;
			dis[vet[i]]=dis[x]+1;
			if (dis[vet[i]]>k)	return puts("-1"),0;
			if (!vis[vet[i]])	q[ta=ta%n+1]=make_pair(dis[vet[i]],vet[i]),vis[vet[i]]=1;
		}vis[x]=0;
	}
	For(i,1,n)	printf("%d ",max(1,dis[i]));
}


#include<queue>
#include<ctime>
#include<vector>
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<memory.h>
#include<map>
#include<ctime>
#include<algorithm>
#include<ctime>
#include<set>
#define ll int
#define For(i,j,k)  for(ll i=j;i<=k;++i)
#define FOr(i,j,k)  for(ll i=j;i>=k;--i)
#define ld double
using namespace std;
inline ll read(){   ll x=0,f=1;char ch=getchar();   while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}  while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}  return x*f; }
inline void wrote(ll x){    if (x<0) putchar('-'),x=-x; if (x>=10) wrote(x/10);   putchar(x%10+'0');  }
inline void writeln(ll x){ wrote(x);   puts("");   }
const ll N=400010;
vector<pair<ll,ll> >g[N];
priority_queue<pair<ll,ll> >Q;
ll head[N],nxt[N],vet[N],dfn[N],q[N],rk[N],mx[N],mn[N],n,m,k,top,tot=1;
inline void insert(ll x,ll y){	nxt[++tot]=head[x];	head[x]=tot;	vet[tot]=y;	}
int main(){
	n=read();	m=read();	k=read();
	For(i,1,n)	rk[i]=read(),mx[i]=rk[i]?rk[i]:k,mn[i]=rk[i]?rk[i]:1;
	For(i,1,m){	ll x=read(),y=read();	insert(x,y);	insert(y,x);	++dfn[y];	}
	For(i,1,n)	if (!dfn[i])	q[++top]=i;
	For(now,1,top)	for(ll i=head[q[now]];i;i=nxt[i])	if (i%2==0)	if (!--dfn[vet[i]])	q[++top]=vet[i];
	if (top!=n)	return puts("-1"),0;
	For(now,1,top)	for(ll i=head[q[now]];i;i=nxt[i])	if (i%2==0)	mx[vet[i]]=min(mx[vet[i]],mx[q[now]]-1);
	FOr(now,top,1)	for(ll i=head[q[now]];i;i=nxt[i])	if (i%2==1)	mn[vet[i]]=max(mn[vet[i]],mn[q[now]]+1);
	For(i,1,n)	if (mx[i]<mn[i])	return puts("-1"),0;	else	g[mx[i]].push_back(make_pair(mn[i],i));
	FOr(i,k,1){
		for(ll j=0;j<g[i].size();j++)	Q.push(g[i][j]);
		if (Q.empty())	return puts("-1"),0;
		rk[Q.top().second]=i;	Q.pop();
		while(!Q.empty()&&Q.top().first==i)	rk[Q.top().second]=i,Q.pop();
	}
	For(i,1,n)	printf("%d ",rk[i]);
}


#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],D[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++) D[i]=d[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;}
	for (int i=1;i<=n;i++) if (dp[i]>k) {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();
	  }

	l=r=0;
	for (int i=1;i<=n;i++) dp[i]=a[i],d[i]=D[i];
	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];
		}
	}
	for (int i=1;i<n;i++) printf("%d ",dp[i]);printf("%d\n",dp[n]);
	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],D[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++) D[i]=d[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();
	  }

	l=r=0;
	for (int i=1;i<=n;i++) dp[i]=a[i],d[i]=D[i];
	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];
		}
	}
	for (int i=1;i<n;i++) printf("%d ",dp[i]);printf("%d\n",dp[n]);
	return 0;
}


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

using namespace std;

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

int n,m,k;
int d[maxn],dp[maxn],q[maxn];
int head[maxn],to[maxn],nxt[maxn];
int num;
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;
}

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

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);
	}
	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;}
	r=0;
	for (int i=1;i<=n;i++) if (!a[i]) b[++r]=(yts){i,dp[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].w>i) now++;
	  	if (now==r+1) {puts("-1");return 0;}
	  	a[b[now++].id]=i;
	  }
	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>
#define maxn 200010

using namespace std;

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

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.w>y.w || (x.w==y.w && 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].w>i || b[now].w1<i)) now++;
	  	if (now==r+1) {puts("-1");return 0;}
	  	a[b[now++].id]=i;
	  }
	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;
}