HDU 1878 Euro-Pull loop water problem. The test data seems a bit problematic.

Source: Internet
Author: User

Euler circuitTime limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 10135 Accepted Submission (s): 3708


Problem description is a loop that does not leave the pen on the 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?
The input test inputs contain 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 input knot
Beam.
Output takes one row for each test case, and outputs 1 if the Euler loop is present, otherwise outputs 0.

Sample Input
3 31 21 32 33 21 22 30

Sample Output
10
Specially read a lot of books, the definition of the Euro-loop is a little puzzled, if there is an isolated point in the figure, and in addition to this point other than the point is to meet the European pull circuit, that this survival does not exist in the European pull circuit? After all, this isolated point has no edge, the other point structure does not constitute Euler loop has no effect ah. But this problem does not need to consider this situation ... I do not know whether it is data water, or I understand the definition of the Euler circuit has a problematic code:
#include <cstdio> #include <cstring> #include <queue> #define SIZE 1010using namespace std; bool graph[ Size][size], vis[size];int degree[size]; bool BFS (int pos, int n) {queue<int> que; Que.push (POS); while (!que.empty ( ) {int tmp = Que.front (); Que.pop (); for (int i = 1; I <= n; ++i) {if (!vis[i] && graph[tmp][i]) {vis[i] = true; Que.push (i);}}} for (int i = 1; I <= n; ++i) {if (!vis[i]) return false;} return true;} int main () {int n, m, while (~SCANF ("%d", &n) && N) {scanf ("%d", &m); memset (graph,false,sizeof (graph)); memset (degree,0,sizeof (degree)); for (int i = 0; i < m; ++i) {int x, y; scanf ("%d%d", &x,&y); Graph[x][y] = Grap H[y][x] = True;d egree[x]++, degree[y]++;} BOOL flag = True  ; for (int i = 1, i <= N; ++i) {if (degree[i]%2!=0) {flag = false; break;}} if (!flag) puts ("0"), else if (BFS (1,n)) {puts ("1");} Elseputs ("0");} return 0;}

with June

HDU 1878 Euro-Pull loop water problem. The test data seems a bit problematic.

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.