hiho第四十九周——欧拉路·一
题目链接:http://hihocoder.com/contest/hiho49/problem/1
欧拉路证明:http://class.htu.cn/lisanshuxue/neirong/7_4.htm
注意点
1、给定无孤立结点图G,若存在一条路,经过图中每边一次且仅一次,该条路称为欧拉路。
2、欧拉路判定条件:(1)一个无向图存在欧拉路当且仅当该图是连通的且有且只有2个点的度数是奇数,此时这两个点只能作为欧拉路径的起点和终点。(2)若图中没有奇数度的点,那么起点和终点一定是同一个点,这样的欧拉路叫做欧拉回路
可执行代码
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream cin("input.txt");
int N,M;//岛屿数,桥数
cin>>N>>M;
if(N<2)
{
cout<<"Full"<<endl;
return 0;
}
int * degree = new int[N];
for(int i = 0;i<N;i++)
degree[i] = 0;
int Is1,Is2;
for(int i = 0;i<M;i++)
{
cin>>Is1>>Is2;
degree[Is1-1]++;
degree[Is2-1]++;
}
int odd = 0;
int i =0;
while(i<N && degree[i]!=0)
{
if(degree[i]%2!=0)
odd++;
i++;
}
if(i == N && (odd==2 || odd==0))//度为奇数的结点没有或者有且只有两个,且图是连通的
cout<<"Full"<<endl;
else
cout<<"Part"<<endl;//存在度为0的结点,即图是非连通的;或者图是连通的,但度为奇数的结点数不是2或0
return 0;
}