zoukankan      html  css  js  c++  java
  • hihocoder 1176(欧拉路)

    hihocoder 1176

    题意:N,M。分别表示岛屿数量和木桥数量,一笔画

    分析:欧拉路问题(给定无孤立结点图G,若存在一条路,经过图中每边一次且仅一次,该条路称为欧拉路)

    欧拉路的条件

    1. 一个无向图存在欧拉路当且仅当该图是连通
    2. 且只有2个点的度数是奇数(此时这两个点只能作为欧拉路径的起点和终点

    用并查集判断第一个条件

    第二个直接用数组存

     1 #include <iostream>
     2 #include <cmath>
     3 #include <cstdio>
     4 #include <cstring>
     5 #include <string>
     6 #include <map>
     7 #include <iomanip>
     8 #include <algorithm>
     9 #include <queue>
    10 #include <stack>
    11 #include <set>
    12 #include <vector>
    13 //const int maxn = 1e5+5;
    14 #define ll long long
    15 #define MAX INT_MAX
    16 #define FOR(i,a,b) for( int i = a;i <= b;++i)
    17 using namespace std;
    18 int fh[11000],degree[11000];
    19 int n,m,cnt1,cnt2,a,b;
    20 int findhead(int k)  //并查集判断条件一
    21 {
    22     if(fh[k]==-1)
    23         return k;
    24      return fh[k]=findhead(fh[k]);
    25 }
    26 int main()
    27 {
    28     //    freopen("D:\common_text\code_stream\in.txt","r",stdin);
    29     //    freopen("D:\common_text\code_stream\out.txt","w",stdout);
    30     cin>>n>>m;
    31     memset(fh,-1,sizeof(fh));
    32     for(int i=1;i<=m;++i)
    33     {
    34         cin>>a>>b;
    35         degree[a]++;
    36         degree[b]++;
    37         a=findhead(a);
    38         b=findhead(b);
    39 
    40         if(a!=b)
    41             fh[a]=b;
    42     }
    43     for(int i=1;i<=n;++i)
    44     {
    45         if(findhead(i)==i)
    46         {
    47             cnt1++;
    48         }
    49         if(degree[i]%2==1)
    50         {
    51             cnt2++;
    52         }
    53     }
    54     //cout<<cnt1<<"   "<<cnt2<<endl;
    55     if(cnt1==1&&(cnt2==0||cnt2==2))  //head点只有一个切 度奇数点为2或者0
    56     {
    57         cout<<"Full";
    58     }
    59     else cout<<"Part";
    60 
    61 
    62 }
  • 相关阅读:
    windows防火墙失效
    unity_animator_stop_replay(重新播放)
    使用rider做为unity的代码编辑器
    分母为0的坑(float)
    动画或特效不会播放(被裁剪)
    UGUI在两个UI间坐标转换
    informix 查看 当前锁表
    java protected 与默认权限的区别
    Java 定时任务
    在线支付
  • 原文地址:https://www.cnblogs.com/jrfr/p/10739697.html
Copyright © 2011-2022 走看看