-
Title Description:
The
-
Euler circuit refers to a loop that does not leave the pen on paper, but only once per side of the picture and can return to the starting point. Now given a diagram, ask if there is a Euler circuit?
-
Input:
The
-
test input contains several test cases. The 1th line of each test case gives two positive integers, namely the number of nodes N (1 < N < 1000) and the number of sides m, followed by M-bars, each with a pair of positive integers, the number of two nodes (nodes from 1 to N) that are directly connected to the bar. When n is 0 o'clock, the input ends.
-
Output:
-
the output of each test case is one row, or output 1 if the Euler loop is present, otherwise output 0.
-
Sample input:
-
3 31 21 32 33 21 22 30
-
Sample output:
-
10
-
-
Source:
-
-
2008 Zhejiang University computer and software engineering research on the real problem of life test
-
#include <iostream> #include <fstream> #include <cstring> using namespace std; int g[1000][1000]; int main () {int n, m; int x, Y, I, J; int sum; while (CIN >> N) {if (!n) break; Cin >> m; memset (g, 0, n*n); for (i = 0; i < m; i++) {cin >> x >> y; G[X-1][Y-1] = 1; G[Y-1][X-1] = 1; } for (i = 0; i < n; i++) {sum = 0; for (j = 0; J < N; j + +) sum + = G[i][j]; if (sum% 2 = = 1) {cout << ' 0 ' << Endl; Break }} if (i = = N) cout << ' 1 ' << Endl; }}/************************************************************** problem:1027 User:carvin language:c++ Res ult:accepted time:130 Ms memory:5424 kb****************************************************************/
Topic 1027: Euler circuits