Topic 1027: Euler circuits

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.