zoukankan      html  css  js  c++  java
  • hoj1878

    看是否所有定点的度都是偶数,并使用并查集看图是否连通。我开始因为没有判断是否连通而错了许多次。

    View Code
    #include <iostream>
    #include
    <cstdio>
    #include
    <cstdlib>
    #include
    <cstring>
    using namespace std;

    #define maxn 1005

    int n, m, f[maxn], father[maxn];

    int getanc(int a)
    {
    if (father[a] == a)
    return a;
    return father[a] = getanc(father[a]);
    }

    bool ok()
    {
    for (int i = 0; i < n; i++)
    if (f[i] % 2 != 0 || getanc(i) != getanc(0))
    return false;
    return true;
    }

    int main()
    {
    //freopen("D:\\t.txt", "r", stdin);
    while (scanf("%d", &n) != EOF && n != 0)
    {
    scanf(
    "%d", &m);
    for (int i = 0; i < n; i++)
    father[i]
    = i;
    memset(f,
    0, sizeof(f));
    for (int i = 0; i < m; i++)
    {
    int a, b;
    scanf(
    "%d%d", &a, &b);
    a
    --;
    b
    --;
    father[getanc(a)]
    = getanc(b);
    f[a]
    ++;
    f[b]
    ++;
    }
    if (ok())
    printf(
    "1\n");
    else
    printf(
    "0\n");
    }
    return 0;
    }
  • 相关阅读:
    js1
    curl获取图片
    TP中讲的两种ajax方法
    tp验证码
    TP上传图片
    TP中登录验证
    tp中自定义跳转页面
    用户数据库表状态一类的问题
    用php实现斐波那契数列
    微信的网页授权登陆
  • 原文地址:https://www.cnblogs.com/rainydays/p/1999160.html
Copyright © 2011-2022 走看看