Aqua loves painting

Aqua is five years now! She loves painting very much, and after day by day to paint, she
finds a question:
Can I paint the picture by just one stroke?
In some other words, there are ?? points in the picture and are connected by ?? edges.
She needs to find if she can paint the picture by one stroke, which means if she can paint all the edges in the picture by one stroke.
Note that two unconnected points can’t be painted from one to another by one stroke,
and every edge must only be painted once.
You need to tell her if she can paint the picture by just one stroke, and if she can’t, tell her the minimum number of strokes she needs to paint the picture.
Input
The first line contains two integers ?? (1 ≤ ?? ≤ 200000) indicating the number of points
and ?? (1 ≤ ?? ≤ 1000000) indicating the number of edges.
Then followed by m lines each line contains two integers x, y indicating there is an edge
between point ?? and point ?? (1 ≤ ??, ?? ≤ ??).
It is guaranteed that there are no two completely identical edges.
Output
If she can paint the picture by one stroke just print YES.
Otherwise print NO, then followed by one line contains one integer, the minimum number
of strokes she needs to paint all the points in the picture.
Sample input and output

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Sample Input
4 5
1 2
1 3
1 4
2 3
3 4
Sample Output
YES
Sample Input
5 5
1 2
2 3
2 4
3 4
4 5
Sample Output
NO
2

Note
In the first test case, she can start with point 1 and paints by 1 → 2 → 3 → 4, so she can
paint the picture by just one stroke, so the answer is YES.
In the second test case, it is proved she can’t paint the picture by just one stroke and the
minimum number of strokes is 2. One optional way to paint the picture is:
First stroke: 1 → 2 → 3 → 4 → 5
Second stroke: 2 → 4
HDU 3018 原题
这道题其实还是有坑点的,首先"paint all the edges in the picture by one stroke",题意是画边,不是画点,孤立点不需要画。然后"If she can paint the picture by one stroke just print YES.",一笔画的时候输出YES,没有边的图输出NO和0.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <bits/stdc++.h>

using namespace std;
const int N = 2e5 + 10, M = 1e6 + 10;
int head[N], ver[M << 1], Next[M << 1], tot;
int n, m, deg[N];
bool v[N];
int cnt, ans;

inline void add(int x, int y) {
    ver[++tot] = y;
    Next[tot] = head[x];
    head[x] = tot;
}

inline void read() {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= m; i++) {
        int x, y;
        scanf("%d%d", &x, &y);
        add(x, y), add(y, x);
        deg[x]++, deg[y]++;
    }
}

void dfs(int x) {
    v[x] = true;
    if (deg[x] & 1)cnt++;
    for (int i = head[x]; i; i = Next[i]) {
        int y = ver[i];
        if (v[y])continue;
        dfs(y);
    }
}

int main() {
    read();
    for (int i = 1; i <= n; i++)
        if (!v[i]) {
            if (!deg[i])continue;
            ans++, cnt = 0, dfs(i);
            if (cnt > 2)ans += (cnt - 2) / 2;
        }
    ans == 1 ? puts("YES") : printf("NO\n%d\n", ans);
    return 0;
}