
题意:给出n个岛,每个岛都有桥到达其他岛,且桥数可多可少(即使两岛有多桥),判断是否是欧拉路(即每条桥只能走一次,所有桥都能遍历1遍)。
思路:
满足如下条件之一者即为欧拉路:
1、连通图,每个岛的度数为偶数。
2、连通图,其中仅两个岛的度数为奇数,其他都是偶数。
#include <bits/stdc++.h>
using namespace std;
const int N=;
vector< vector<int> > vect;
bool vis[N];
int n,m,a,b; void DFS(int t) //遍历一遍所有点
{
vis[t]=true;
for(int i=; i<vect[t].size(); i++)
{
if(!vis[vect[t][i]])
DFS(vect[t][i]);
}
} bool check() //判断是否为连通图
{
for(int i=; i<=n; i++)
if(!vis[i])
return false;
return true;
} bool conj() //判断是否为两个奇数/全偶数情况。
{
int odd=, even=;
for(int i=; i<=n; i++)
if((vect[i].size()&)==) //奇数
odd++;
else even++;
if(odd==||odd==) return true;
else return false;
} int main()
{
//freopen("input.txt","r",stdin);
vector<int> tmp;
cin>>n>>m;
for(int i=; i<=n; i++) vect.push_back(tmp);
for(int i=; i<m; i++)
{
scanf("%d%d",&a,&b);
vect[a].push_back(b);
vect[b].push_back(a);
}
DFS();
if(check()==false) printf("Part\n");
else if(conj()) printf("Full\n");
else printf("Part\n"); return ;
}
AC代码