日本最強プログラマー学生選手権~Advance~ -予選- (AtCoder Beginner Contest 412)
G
Degree Harmony
AtCoder
⌀ 3402
原题
翻译中…

Problem Statement

翻译中…

You are given a simple undirected graph $G$ with $N$ vertices and $M$ edges, where vertices are numbered from $1$ to $N$. The $i$-th edge connects vertices $u_i$ and $v_i$. A spanning subgraph $G'$ of $G$ that satisfies the following condition is called a good graph:

翻译中…
  • For all integers $i$ satisfying $1 \leq i \leq N$, the following condition holds:
  • Let $d_i$ be the degree of vertex $i$ in $G'$. Then, $d_i \leq A_i$ and $d_i \bmod 2 = A_i \bmod 2$ hold.
翻译中…

Determine whether a good graph exists. If it exists, output the minimum number of edges among all possible good graphs.

翻译中…

Constraints

翻译中…
  • $1 \leq N \leq 150$
  • $0 \leq M \leq \frac{N(N-1)}{2}$
  • $1 \leq u_i < v_i \leq N$
  • The given graph is simple.
  • $1 \leq A_i \leq 150$
  • $1 \leq \sum_{i=1}^N A_i \leq 150$
  • All input values are integers.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

N M
A_1 A_2 \dots A_N
u_1 v_1
u_2 v_2
\vdots
u_M v_M

翻译中…

Output

翻译中…

If no good graph exists, output -1. If it exists, output the minimum number of edges among all possible good graphs.

翻译中…

样例

Input #1
3 3
1 2 3
1 2
1 3
2 3
Output #1
1
The spanning subgraph whose edge set consists of only the $2$nd edge is a good graph.
Input #2
4 3
1 1 1 1
1 3
2 3
3 4
Output #2
-1
Input #3
5 6
3 1 4 3 1
1 2
1 3
1 4
2 3
3 4
3 5
Output #3
3
题目信息

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。