一本通1533:相框

#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;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值