Problem Description
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
5 5
2 3
4 1
1 5
5 3
2 1
1 1 2 0 2Output
2
1 2Input
4 2
1 2
3 4
0 0 0 0Output
3
1 3 4
题意:有编号 1~n 的 n 个点,存在 m 条边,每个点初始时为 0,存在一个 ai 值,当打击第 i 个点时,与 i 直接相邻的点会 +1,问打击哪些点会使得所有的计数器不等于对应的 ai
思路:借助队列,将 点值=ai 的点存入,然后去枚举其相邻的点 ,当等于 ai 时就加入队列,然后记录答案
Source Program
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 500000+5;
const int dx[] = {-1,1,0,0,-1,-1,1,1};
const int dy[] = {0,0,-1,1,-1,1,-1,1};
using namespace std;
vector<int> G[N];
queue<int> Q;
int res[N];
int a[N];
int num[N];
int main() {
int n,m;
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++) {
int x,y;
scanf("%d%d",&x,&y);
G[x].push_back(y);
G[y].push_back(x);
}
int tot=0;
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
if(a[i]==0){
res[++tot]=i;
Q.push(i);
}
}
while(!Q.empty()){
int x=Q.front();
Q.pop();
for(int y=0;y<G[x].size();y++){
int temp=G[x][y];
num[x]++;
num[temp]++;
if(a[temp]==num[temp]){
Q.push(temp);
res[++tot]=temp;
}
}
}
printf("%d\n",tot);
sort(res+1,res+1+tot);
for(int i=1;i<=tot;i++)
printf("%d ",res[i]);
printf("\n");
return 0;
}