#include <bits/stdc++.h>
namespace fastIO {
const int LEN = (1 << 20);
#ifdef ONLINE_JUDGE
inline int nec(void) {
static char buf[LEN], *p = buf, *e = buf;
if (p == e) {
e = buf + fread(buf, 1, LEN, stdin);
if (e == buf)
return EOF;
p = buf;
}
return *p++;
}
#else
#define nec getchar
#endif
inline bool read(int &x) {
x = 0;
bool f = 0;
char ch = nec();
while (ch < '0' || ch > '9') {
if (ch == EOF)
return 0;
if (ch == '-')
f = 1;
ch = nec();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = nec();
}
if (f)
x = -x;
return 1;
}
void print(int x) {
if (x < 0) {
putchar('-');
x = -x;
}
if (x >= 10)
print(x / 10);
putchar(x % 10 + '0');
return;
}
void print(int x, char ch) {
print(x);
putchar(ch);
return;
}
} // namespace fastIO
namespace XSC062 {
using namespace fastIO;
const int maxn = 1e3 + 5;
int deg[maxn];
bool vis[maxn];
std::vector<int> g[maxn];
int n, m, x, y, tot, res, cnt, flag;
void add(int x, int y) {
g[x].push_back(y), ++deg[y];
return;
}
void DFS(int x) {
vis[x] = 1;
tot += (deg[x] & 1);
if (deg[x] > 2)
++flag;
for (auto i : g[x]) {
if (i && !vis[i])
DFS(i);
else if (i == 0)
++tot;
}
return;
}
int main() {
read(n), read(m);
while (m--) {
read(x), read(y);
if (x + y == 0)
++res;
else
add(x, y), add(y, x);
}
for (int i = 1; i <= n; ++i) {
if (!deg[i])
continue;
if (!vis[i]) {
flag = 0, tot = 0, DFS(i);
res += flag;
if (tot) {
cnt += tot;
continue;
}
res += 2 - (bool)flag;
}
}
res += cnt / 2 + ((cnt & 1) << 1);
print(res, '\n');
return 0;
}
} // namespace XSC062
int main() {
XSC062::main();
return 0;
}
一本通1533:相框
最新推荐文章于 2025-07-24 20:33:53 发布