Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define ld long double
- #define pb push_back
- #define all(n) n.begin(),n.end()
- #define eb emplace_back
- #define endl "\n"
- #define pll pair<ll,ll>
- #define ff first
- #define ss second
- const ll maxn=5e5+50;
- const ll maxx=1e13;
- const ll mod=1000000007;
- const ll mod1=998244353;
- pll a[maxn];
- ll c[maxn];
- vector<ll> adj[maxn];
- vector<ll>ans[maxn];
- int main()
- {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- //freopen("test.txt","r",stdin);
- if (fopen("FAIR.INP","r"))
- {
- freopen("FAIR.INP", "r", stdin);
- freopen("FAIR.OUT", "w", stdout);
- }
- ll n,m ;
- cin>> n>> m ;
- for (int i=1;i<=m;i++)
- {
- cin>>a[i].ff>>a[i].ss;
- }
- for (int i=1;i<=n;i++)
- {
- cin>>c[i];
- ans[c[i]].pb(i);
- }
- for (int i=1;i<=m;i++)
- {
- if (c[a[i].ff]==c[a[i].ss])
- {
- // cout <<"wtf";
- cout <<-1;
- return 0;
- }
- adj[a[i].ff].pb(c[a[i].ss]);
- adj[a[i].ss].pb(c[a[i].ff]);
- }
- for (int i=1;i<=n;i++)
- {
- map<ll,ll> dd;
- for (auto to:adj[i])
- {
- dd[to]=1;
- }
- for (int j=1;j<c[i];j++)
- {
- if (dd[j]==0)
- {
- // cout <<"wtf";
- cout <<-1;
- return 0;
- }
- }
- }
- vector<ll> ans1;
- for (int i=1;i<=n;i++)
- {
- for (auto to:ans[i])
- {
- ans1.pb(to);
- }
- }
- for (auto p:ans1)
- {
- cout <<p<<" ";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment