fork download
  1. //NiceDuck
  2. #include "bits/stdc++.h"
  3. typedef long long ll;
  4. using namespace std;
  5. #define FILE "000"
  6. #define foru(i,a,b) for(int i=(int)(a); i<=(int)(b); ++i)
  7. #define ford(i,a,b) for(int i=(int)(a); i>=(int)(b); --i)
  8. #define fastio ios_base::sync_with_stdio(0);cin.tie(0);
  9. #define pb push_back
  10. #define fi first
  11. #define se second
  12. #define pii pair<int,int>
  13. #define pil pair<int,ll>
  14. #define pli pair<ll,int>
  15. #define MOD 1000000007
  16. #define el "\n"
  17. #define MAX 200005
  18.  
  19. const int INF=1e9;
  20.  
  21. int n,m,k,dist[MAX],d[MAX],a[MAX];
  22. vector<int> adj[MAX];
  23.  
  24. void calc()
  25. {
  26. dist[1]=0;
  27. foru(i,2,n) dist[i]=INF;
  28. queue<int> q;
  29. q.push(1);
  30. while(!q.empty())
  31. {
  32. int u=q.front(); q.pop();
  33. for(int v:adj[u])
  34. {
  35. if(dist[v]>dist[u]+1)
  36. {
  37. dist[v]=dist[u]+1;
  38. d[a[v]]=max(d[a[v]],dist[v]);
  39. q.push(v);
  40. }
  41. }
  42. }
  43. foru(i,1,k) cout<<d[i]<<' ';
  44. }
  45.  
  46. int main()
  47. {
  48. fastio
  49. #ifndef ONLINE_JUDGE
  50. freopen(FILE ".inp","r",stdin);
  51. freopen(FILE ".out","w",stdout);
  52. #endif // ONLINE_JUDGE
  53.  
  54. cin>>n>>m>>k;
  55. foru(i,1,n) cin>>a[i];
  56. foru(i,1,m)
  57. {
  58. int u,v; cin>>u>>v;
  59. adj[u].pb(v);
  60. adj[v].pb(u);
  61. }
  62. calc();
  63.  
  64. return 0;
  65. }
Success #stdin #stdout 0.01s 10120KB
stdin
Standard input is empty
stdout
Standard output is empty