PAT甲级 1126 - Eulerian Path
2018-03-01 17:47
393 查看
根据题目所给的条件进行判断即可。
It has been proven that connected graphs with all vertices of even degree have an Eulerian circuit, and such graphs are called Eulerian. 在图联通的前提下,节点的入度和出度均为偶数。
If there are exactly two vertices of odd degree, all Eulerian paths start at one of them and end at the other. 在图联通的前提下,节点的入度和出度exactly两个奇数。
A graph that has an Eulerian path but not an Eulerian circuit is called semi-Eulerian 其他的就是费Eulerian path。
It has been proven that connected graphs with all vertices of even degree have an Eulerian circuit, and such graphs are called Eulerian. 在图联通的前提下,节点的入度和出度均为偶数。
If there are exactly two vertices of odd degree, all Eulerian paths start at one of them and end at the other. 在图联通的前提下,节点的入度和出度exactly两个奇数。
A graph that has an Eulerian path but not an Eulerian circuit is called semi-Eulerian 其他的就是费Eulerian path。
#include<bits/stdc++.h> using namespace std; const int maxn=500+3; vector<int> edge[maxn]; int degree[maxn]; bool visited[maxn]; void dfs(int cur){ for(vector<int>::iterator it = edge[cur].begin();it!=edge[cur].end();++it){ if(!visited[*it]){ visited[*it]=true; dfs(*it); } } } bool isConnected(int n){ dfs(1); visited[1]=true; for(int i=1;i<=n;++i){ if(!visited[i])return false; } return true; } int main(){ int n,m; scanf("%d %d",&n,&m); int u,v; for(int i=0;i<m;++i){ scanf("%d %d",&u,&v); edge[u].push_back(v),edge[v].push_back(u); ++degree[v],++degree[u]; } int cntOdd=0; bool flag = isConnected(n); for(int i=1;i<=n;++i){ if(i==1)printf("%d",degree[i]); else printf(" %d",degree[i]); cntOdd+=(degree[i]%2); } printf("\n"); if(cntOdd==0 && flag){ printf("Eulerian"); }else if(cntOdd==2 && flag){ printf("Semi-Eulerian"); }else{ printf("Non-Eulerian"); } return 0; }
相关文章推荐
- 1126. Eulerian Path (25) PAT 甲级
- pat 甲级 1126. Eulerian Path java实现
- PAT甲级 1126. Eulerian Path (25)
- PAT 1126. Eulerian Path (25)-甲级
- PAT - 甲级 - 1126. Eulerian Path (25)
- PAT 甲级 1126. Eulerian Path (25)
- PAT (Advanced Level) Practise 1126 Eulerian Path (25)
- PAT (Advanced Level) 1126. Eulerian Path (25)
- PAT1126. Eulerian Path (25) 判断图是否连通,求各点的度
- PAT_A 1126. Eulerian Path (25)
- PAT:1126. Eulerian Path (25)
- PAT--1126. Eulerian Path
- pat 甲1126. Eulerian Path (欧拉图的判定)
- 【PAT-A】1126. Eulerian Path (25)
- PAT 1126. Eulerian Path (25)
- PAT(A)-1126. Eulerian Path (25)(欧拉图的判断)
- PAT甲题题解-1126. Eulerian Path (25)-欧拉回路+并查集判断图的连通性
- PAT 1126. Eulerian Path (25)
- 【PAT】【Advanced Level】1126. Eulerian Path (25)
- PAT (Advanced Level) 1126. Eulerian Path (25) 解题报告