题目看着好吓人好吓人。
其实呢。。
就是统计度的个数和图是否联通。。。。。
#include <iostream>#include <vector>#include <cstring>#include <algorithm>#define MAX 510using namespace std;vector <int> g[MAX];int v, e;bool isVis[MAX];void DFS(int st) { isVis[st] = true; for (int i = 0; i < g[st].size(); i++) { if(!isVis[g[st][i]]) DFS(g[st][i]); }}bool DFSTrave() { int count = 0; for (int i = 1; i <= v; i++) { if (!isVis[i]) DFS(i),count++; } return count == 1;}int main() { int x, y; cin >> v >> e; for (int i = 0; i < e; i++) { cin >> x >> y; g[x].push_back(y); g[y].push_back(x); } memset(isVis, false, sizeof(isVis)); int odd = 0, even = 0; for (int i = 1; i < v; i++) { if (g[i].size() % 2 == 0) { even++; } else { odd++; } cout << g[i].size() << " "; } if (g[v].size() % 2 == 0) even++; else odd++; cout << g[v].size() << endl; bool tag = DFSTrave(); if (odd == 0 && tag) cout << "Eulerian" << endl; else if (odd == 2 && tag) cout << "Semi-Eulerian" << endl; else cout << "Non-Eulerian" << endl; return 0;}
新闻热点
疑难解答