zoukankan      html  css  js  c++  java
  • TOJ3649欧拉回路

    欧拉回路 分享至QQ空间 去爱问答提问或回答

    Time Limit(Common/Java):1000MS/3000MS     Memory Limit:65536KByte
    Total Submit: 35            Accepted: 20

    Description

     

    欧拉回路是指不令笔离开纸面,可画过图中每条边仅一次,且可以回到起点的一条回路。现给定一个图,问是否存在欧拉回路?

     

    Input

     

    测试输入包含若干测试用例。每个测试用例的第1行给出两个正整数,分别是节点数N ( 1 < N < 1000 )和边数M;随后的M行对应M条边,每行给出一对正整数,分别是该条边直接连通的两个节点的编号(节点从1到N编号)。当N为0时输入结
    束。

     

    Output

     

    每个测试用例的输出占一行,若欧拉回路存在则输出1,否则输出0。
     

     

    Sample Input

     

    3 3
    1 2
    1 3
    2 3
    3 2
    1 2
    2 3
    0
    

     

    Sample Output

     

    1
    0
    

     

     

    #include <iostream>
    #include <queue>
    #include <string>
    #include <cstdio>
    #include <cstring>
    #include <vector>
    #include <stack>
    #include <algorithm>
    using namespace std;
    const int maxn = 1100;
    
    int cnt[maxn];
    int gn, gm;
    
    int main()
    {
        int i;
        int from, to;
        while(scanf("%d%d", &gn, &gm) != EOF && gn) {
            memset(cnt, 0, sizeof(cnt));
            for(i = 0; i < gm; i++) {
                scanf("%d%d", &from, &to);
                cnt[from]++;
                cnt[to]++;
            }
            for(i = 1; i <= gn; i++) {
                if(cnt[i]%2==0 && cnt[i] != 0) continue;
                else {
                    printf("0
    ");
                    break;
                }
            }
            if(i==gn+1) {
                printf("1
    ");
            }
        }
        return 0;
    }
  • 相关阅读:
    java跳过构造方法新建对象
    java实现类似qq的窗口对聊
    NoSql的产生
    C语言跳出循环
    C语言for循环
    C语言while语句
    C语言条件运算符
    C语言switch语句
    C语言逻辑运算符
    C语言关系运算符
  • 原文地址:https://www.cnblogs.com/suncoolcat/p/3285847.html
Copyright © 2011-2022 走看看