Advertisement
Guest User

Untitled

a guest
Mar 20th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int n,m,a,b,w,v;
  5. int odw[1000006],t[1000006],odleglosc[1000006];
  6. vector <int> G[1000006];
  7. queue <int> q;
  8.  
  9. int main()
  10. {
  11.     ios_base::sync_with_stdio(0);
  12.     cin.tie(0);
  13.     cout.tie(0);
  14.  
  15.     cin>>n>>m;
  16.  
  17.     for(int i = 1; i <= n; i++)
  18.     {
  19.         cin>>t[i];
  20.         if(t[i] == 1)  q.push(i);
  21.     }
  22.  
  23.     for(int i = 1; i <= m; i++)
  24.     {
  25.         cin>>a>>b;
  26.         G[a].push_back(b);
  27.         G[b].push_back(a);
  28.     }
  29.  
  30.     while(!q.empty())
  31.     {
  32.         w = q.front();
  33.         q.pop();
  34.         for(int i = 0; i < G[w].size(); i++)
  35.         {
  36.             v = G[w][i];
  37.             if(odw[v] == 0)
  38.             {
  39.                 odw[v] = 1;
  40.                 q.push(v);
  41.             }
  42.         }
  43.     }
  44.  
  45.  
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement