CF--Dispute--队列

D. Dispute

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 a1, a2, ..., an. 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 ai, 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 ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi), that mean that counters with numbers ui and vi 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 a1, a2, ..., an (0 ≤ ai ≤ 105), where ai 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

Copy

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

output

Copy

2
1 2

input

Copy

4 2
1 2
3 4
0 0 0 0

output

Copy

3
1 3 4

题意:给出点和边,点的计数器初始为0,各个点有一个值ai。当打击第i个点时,和i直接相邻的点会计数器+1,。问击打哪些点会使得所有的计数器值不等于对应的ai。

用一个队列首先存入计数器值=ai的点、然后枚举其相邻的点,=ai则加入队列,进入队列的点一定不可能再次进入队列。

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=100000+66;
const ll mod=1e9+7;
int n,m;
/*struct node
{
    int id;
    int v;
}a[maxn];*/
int a[maxn];
int b[maxn];
vector<int>g[maxn];
queue<int>q;
int r[maxn];

int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1; i<=m; i++)
    {
        int u,v;
        scanf("%d %d",&u,&v);
        g[u].push_back(v);
        g[v].push_back(u);
    }
    int maxs=-1;
    for(int i=1; i<=n; i++)
    {
        a[i]=0;
        scanf("%d",&b[i]);
        maxs=max(maxs,b[i]);
    }
    int ans=0;
    for(int i=1; i<=n; i++)
    {
        if(b[i]==a[i])
        {
            q.push(i);
        }
    }
    while(!q.empty())
    {
        ans++;
        int v=q.front();
        r[ans]=v;
        q.pop();
        for(int i=0;i<g[v].size();i++)
        {
            int vv=g[v][i];
            a[vv]++;
            if(a[vv]==b[vv])
                q.push(vv);
        }
    }
    /*for(int i=1; i<=n; i++)
    {
        //cout<<b[4]<<"---"<<a[4]<<endl;
        if(b[i]==a[i])
        {
            a[i]++;
            ans++;
            r[ans]=i;
            for(int j=0; j<g[i].size(); j++)
            {
                int v=g[i][j];
                a[v]++;
            }
        }
    }*/
    printf("%d\n",ans);
    for(int i=1; i<=ans; i++)
    {
        printf("%d ",r[i]);
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值