Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Whenever no of edges is <= 1e6 then if we insert all nodes in a set and each node is accessed exactly once then the loop below runs exactly o(2*m) times ... because all edges are accessed by two of it's connecting nodes exactly two times...... */
- int main()
- {
- booster()
- ///read("input.txt");
- int n,m;cin>>n>>m;
- for(int i = 1;i<=m;i++)
- {
- int a,b;
- cin>>a>>b;
- v[a].pb(b);
- v[b].pb(a);
- }
- set<int>s;
- vi ans;
- for(int i = 1;i<=n;i++)
- {
- cin>>arr[i];
- if(arr[i]==0)s.insert(i);
- }
- while(!s.empty())
- {
- int x = *s.begin();
- s.erase(x);
- if(cnt[x]!=arr[x])continue;
- cnt[x]++;
- ans.pb(x);
- for(auto it : v[x])
- {
- cnt[it]++;
- if(arr[it]==cnt[it])s.insert(it);
- }
- }
- cout<<ans.size()<<endl;
- for(auto it : ans)cout<<it<<" ";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement