• nyoj 一笔画问题 (判断欧拉路径)


    无向图判断欧拉路径只要:

    1.图为连通图(并查集处理)

    2.奇数度为0或2

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstdlib>
     4 #include<cstring>
     5 #include<string>
     6 #include<queue>
     7 #include<algorithm>
     8 #include<map>
     9 #include<iomanip>
    10 #include<climits>
    11 #include<string.h>
    12 #include<cmath>
    13 #include<stdlib.h>
    14 #include<vector>
    15 #include<stack>
    16 #include<set>
    17 using namespace std;
    18 #define INF 1000000007
    19 #define MAXN 4010
    20 #define Mod 1000007
    21 #define N 100010
    22 #define NN 30
    23 #define sigma_size 3
    24 const int MAX = 1000100;
    25 const int maxn = 6e5 + 10;
    26 using namespace std;
    27 typedef long long LL;
    28 
    29 
    30 int T;
    31 int n, m;
    32 int u, v;
    33 int fa[1111];
    34 int deg[1111], one, tot;
    35 
    36 int findset(int x)
    37 {
    38     if (fa[x] == x) return x;
    39     return fa[x] = findset(fa[x]);
    40 }
    41 
    42 void merg(int a, int b)
    43 {
    44     int x = findset(a);
    45     int y = findset(b);
    46     if (x != y) {
    47         fa[x] = y;
    48     }
    49 }
    50 int main()
    51 {
    52     scanf("%d",&T);
    53     while (T--) {
    54         cin >> n >> m;
    55         one = 0, tot = 0;
    56         for (int i = 0; i <= n; ++i) {
    57             fa[i] = i;
    58         }
    59         memset(deg,0,sizeof(deg));
    60         for (int i = 0; i < m; ++i) {
    61             scanf("%d%d", &u, &v);
    62             deg[v]++, deg[u]++;
    63             merg(u,v);
    64         }
    65         for (int i = 1; i <= n; ++i) {
    66             if (deg[i] & 1) one++;
    67             if (fa[i] == i) tot++;
    68         }
    69         if (tot == 1 && (one == 0 || one == 2))
    70             puts("Yes");
    71         else 
    72             puts("No");
    73     }
    74     //system("pause");
    75     return 0;
    76 }
  • 相关阅读:
    RIGHT-BICEP单元测试——“二柱子四则运算升级版”
    个人项目之“二柱子四则运算升级版”(续)
    个人项目之 “二柱子四则运算”升级版
    “进度条”博客
    课后实验3--四则运算3
    构建之法阅读笔记01
    第二周学习进度
    四则运算2单元测试
    课后实验2--四则运算2
    课后实验1--四则运算
  • 原文地址:https://www.cnblogs.com/usedrosee/p/4332027.html
Copyright © 2020-2023  润新知