Dispute(隊列)

 

Valera has n counters numbered from 1 to n. Some of them are connected by wires, and each of the counters has a special button.

Initially, all the counters contain number 0. When you press a button on a certain counter, the value it has increases by one. Also, the values recorded in all the counters, directly connected to it by a wire, increase by one.

Valera and Ignat started having a dispute, the dispute is as follows. Ignat thought of a sequence of n integers a 1, a 2, ..., a n. Valera should choose some set of distinct counters and press buttons on each of them exactly once (on other counters the buttons won't be pressed). If after that there is a counter with the number i, which has value a i, then Valera loses the dispute, otherwise he wins the dispute.

Help Valera to determine on which counters he needs to press a button to win the dispute.

Input

The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 105), that denote the number of counters Valera has and the number of pairs of counters connected by wires.

Each of the following m lines contains two space-separated integers u i and v i (1 ≤ u i, v i ≤ n, u i ≠ v i), that mean that counters with numbers u i and v i are connected by a wire. It is guaranteed that each pair of connected counters occurs exactly once in the input.

The last line contains n space-separated integers a 1, a 2, ..., a n (0 ≤ a i ≤ 105), where a i is the value that Ignat choose for the i-th counter.

Output

If Valera can't win the dispute print in the first line -1.

Otherwise, print in the first line integer k (0 ≤ k ≤ n). In the second line print k distinct space-separated integers — the numbers of the counters, where Valera should push buttons to win the dispute, in arbitrary order.

If there exists multiple answers, you are allowed to print any of them.

Examples

Input

5 5
2 3
4 1
1 5
5 3
2 1
1 1 2 0 2

Output

2
1 2

Input

4 2
1 2
3 4
0 0 0 0

Output

3
1 3 4

 題意:有編號 1~n 的 n 個點,存在 m 條邊,每個點初始時爲 0,每一個點都有一個ai 值,當打擊第 i 個點時,i點 與 i 直接相鄰的點會 +1,問打擊哪些點會使得所有的計數器都不等於 ai

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#define rush() int T;cin>>T;while(T--)
#define go(a) while(cin>>a)
#define ms(a,b) memset(a,b,sizeof a)
#define E 1e-8
using namespace std;
typedef __int64 ll;
const int idata=1e5+5;

int n,m,t,_;
int i,j,k;
//int cnt,num;
int minn,maxx;
queue<int>q;
int ans[idata],num[idata],a[idata];
vector<int>G[idata];

void clear()
{
    queue<int>temp;
    swap(temp,q);
    return ;
}
int main()
{
    cin.tie(0);
    iostream::sync_with_stdio(false);
    while(cin>>n>>m)
    {
        clear();
        ms(num,0);
        for(i=0;i<m;i++){
            int x,y;
            cin>>x>>y;
            //無向圖
            G[x].push_back(y);
            G[y].push_back(x);
        }

        int cnt=0;
        for(i=1;i<=n;i++){
            cin>>a[i];
            if(!a[i]){
                ans[++cnt]=i;
                q.push(i);
            }
        }

        while(!q.empty()){
            int temp=q.front();
            q.pop();
            for(i=0;i<G[temp].size();i++){
                int v=G[temp][i];
                num[temp]++;
                num[v]++;
                if(a[v]==num[v]){
                    q.push(v);
                    ans[++cnt]=v;
                }
            }
        }

        cout<<cnt<<endl;
        sort(ans+1,ans+1+cnt);
        for(i=1;i<=cnt;i++){
            cout<<ans[i]<<" ";
        }
        cout<<endl;
    }
    return 0;
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章