Dang_Quan_10_Tin

Untitled

Jun 4th, 2020
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.70 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3.  
  4. using namespace std;
  5. #define ll long long
  6. #define ld long double
  7. #define pb push_back
  8. #define all(n) n.begin(),n.end()
  9. #define eb emplace_back
  10. #define endl "\n"
  11. #define pll pair<ll,ll>
  12. #define ff first
  13. #define ss second
  14. const ll maxn=5e5+50;
  15.  
  16. const ll maxx=1e13;
  17. const ll mod=1000000007;
  18. const ll mod1=998244353;
  19.  
  20. pll a[maxn];
  21. ll c[maxn];
  22. vector<ll> adj[maxn];
  23. vector<ll>ans[maxn];
  24. int main()
  25. {
  26.     ios_base::sync_with_stdio(0);
  27.     cin.tie(0);
  28.     cout.tie(0);
  29.     //freopen("test.txt","r",stdin);
  30.     if (fopen("FAIR.INP","r"))
  31.     {
  32.         freopen("FAIR.INP", "r", stdin);
  33.         freopen("FAIR.OUT", "w", stdout);
  34.     }
  35.     ll n,m ;
  36.      cin>> n>> m ;
  37.      for (int i=1;i<=m;i++)
  38.      {
  39.          cin>>a[i].ff>>a[i].ss;
  40.      }
  41.      for (int i=1;i<=n;i++)
  42.      {
  43.          cin>>c[i];
  44.          ans[c[i]].pb(i);
  45.  
  46.      }
  47.      for (int i=1;i<=m;i++)
  48.      {
  49.          if (c[a[i].ff]==c[a[i].ss])
  50.          {
  51.             // cout <<"wtf";
  52.              cout <<-1;
  53.              return 0;
  54.          }
  55.          adj[a[i].ff].pb(c[a[i].ss]);
  56.          adj[a[i].ss].pb(c[a[i].ff]);
  57.      }
  58.      for (int i=1;i<=n;i++)
  59.      {
  60.          map<ll,ll> dd;
  61.          for (auto to:adj[i])
  62.          {
  63.              dd[to]=1;
  64.          }
  65.          for (int j=1;j<c[i];j++)
  66.          {
  67.              if (dd[j]==0)
  68.              {
  69.                 // cout <<"wtf";
  70.                  cout <<-1;
  71.                   return 0;
  72.              }
  73.          }
  74.  
  75.      }
  76.      vector<ll> ans1;
  77.      for (int i=1;i<=n;i++)
  78.      {
  79.          for (auto to:ans[i])
  80.          {
  81.              ans1.pb(to);
  82.          }
  83.      }
  84.      for (auto p:ans1)
  85.      {
  86.          cout <<p<<" ";
  87.      }
  88.  
  89. }
Advertisement
Add Comment
Please, Sign In to add comment