Simple Euler circuit, title.
Euler's circuit judgment:
1. In the direction graph: The first necessary condition is that the graph is connected, so the vertex's penetration is equal to the degree of the.
2. In undirected graphs: the first condition or the graph is connected, followed by the vertex is even several (the degree of the vertex is even)
This problem is a graph, so according to the judgment method to write, very simple, the decision does not prove.
I use and check the set to determine whether the diagram is connected.
The following is the code for AC:
#include <iostream> #include <cstring>using namespace Std;int par[1005], Degree[1005];int finds (int x) {if (x = = Par[x]) return X;elsereturn par[x] = finds (Par[x]);} int main () {int A, b, N, M, I;while (CIN >> N) {if (n = = 0) break;for (i = 0; I <= N; i++) Par[i] = i;memset (degree, 0, sizeof (degree)); Cin >> m;for (i = 0; i < m; i++) {cin >> a >> b;degree[a]++; The point degree +1degree[b]++;int x = finds (a), int y = finds (b), if (x! = y) //merge par[x] = y;} int flag = 0, Tag = 0;for (i = 1; I <= n; i++) //whether connected if (par[i] = i) flag++;if (Flag > 1) cout << 0 << Endl;else{for (i = 1; I <= n; i++) //The degree of vertex is even {if (Degree[i]% 2) tag++;} if (Tag > 0) cout << 0 << endl;elsecout << 1 << Endl;}} return 0;}
Hangzhou Electric acm1878--Euler circuit