Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int n,m,a,b,w,v;
- int odw[1000006],t[1000006],odleglosc[1000006];
- vector <int> G[1000006];
- queue <int> q;
- int main()
- {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- cin>>n>>m;
- for(int i = 1; i <= n; i++)
- {
- cin>>t[i];
- if(t[i] == 1) q.push(i);
- }
- for(int i = 1; i <= m; i++)
- {
- cin>>a>>b;
- G[a].push_back(b);
- G[b].push_back(a);
- }
- while(!q.empty())
- {
- w = q.front();
- q.pop();
- for(int i = 0; i < G[w].size(); i++)
- {
- v = G[w][i];
- if(odw[v] == 0)
- {
- odw[v] = 1;
- q.push(v);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement