PAT a1126题解
来源:互联网 发布:永宏编程手册 编辑:程序博客网 时间:2024/06/09 08:47
#include<cstdio> #include<vector> #include<algorithm> using namespace std; const int maxn = 510; int N, M; vector<int> Adj[maxn]; bool vis[maxn] = { false }; int degree[maxn] = { 0 }; int odds = 0, evens = 0; void DFS(int s) { vis[s] = true; for (int i = 0; i < Adj[s].size(); i++) { int v = Adj[s][i]; if (!vis[v]) { DFS(v); } } } int DFStraverse() { int count = 0; for (int i = 1; i <= N; i++) { if (!vis[i]) { count++; DFS(i); } } return count; } int main() { scanf("%d%d", &N, &M); int u, v; for (int i = 0; i < M; i++) { scanf("%d%d", &u, &v); Adj[u].push_back(v); Adj[v].push_back(u); degree[u]++; degree[v]++; } for (int i = 1; i <= N; i++) { if (i > 1)printf(" "); printf("%d", degree[i]); if (degree[i] % 2 == 0)evens++; else odds++; } printf("\n"); if (DFStraverse() == 1) { if (odds == 0)printf("Eulerian"); else if(odds==2)printf("Semi-Eulerian"); else printf("Non-Eulerian"); } else printf("Non-Eulerian"); return 0; }
阅读全文
1 0
- PAT a1126题解
- PAT-A1126
- PAT A1126 Eulerian Path
- Tsinsen A1126 单词接龙
- PAT 1001-1010 题解
- PAT 1011-1020 题解
- PAT 1021-1030 题解
- PAT 1031-1040 题解
- PAT 1041-1050 题解
- PAT 1051-1060 题解
- PAT(basic level)题解
- PAT乙级题解
- PAT题解目录
- PAT甲级题解目录
- PAT乙级题解目录
- PAT甲级1001题解
- PAT甲级1002题解
- PAT b1001-1005题解
- Linux命令详解-sar
- PAT a1124题解
- PAT a1125题解
- 初识Hdoop
- 使用Java实现多线程下载断点续传功能案例
- PAT a1126题解
- python : trans position cipher
- python3编码转换
- PAT a1127题解
- unity3D学习之声音的采集与处理-audio菜鸟笔记1
- PoEdu_Python_Lesson009_类的基础用法、使用dump写数据到json文件的注意点
- 1065. A+B and C (64bit) (20)
- SVM(Support Vector Machine)分类器详解
- 安卓上裁剪m4a | 铃声是怎么制作出来的