Euro-Pull circuitTime
limit:1000MS
Memory Limit:32768KB
64bit IO Format:%i64d &%i64 U
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 input knot
Beam.
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
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include < queue> #include <vector> #include <iomanip> #include <math.h> #include <map>using namespace STD; #define FIN freopen ("Input.txt", "R", stdin), #define FOUT freopen ("Output.txt", "w", stdout); #define INF 0x3f3f 3f3f#define Lson l,m,rt<<1#define Rson m+1,r,rt<<1|1typedef long long ll;const int MAXN=1000+5;int DU[MA Xn];int n,m,sz;int father[maxn];void edge_init () {memset (du,0,sizeof (DU)); for (int i=1;i<=n;i++) {father[i]=i; }}int Find (int x) {if (x!=father[x]) {father[x]=find (father[x]); } return father[x];} int main () {//fin while (~scanf ("%d", &n), N) {scanf ("%d", &m); Edge_init (); int sum=n; for (int i=1;i<=m;i++) {int u,v; scanf ("%d%d", &u,&v); du[u]++; du[v]++; int root1=find (u); int RooT2=find (v); if (Root1!=root2) {father[root2]=root1; sum--; }} if (Sum!=1) {printf ("0\n"); Continue } bool Flag=1; for (int i=1;i<=n;i++) {if (du[i]%2==1) {flag=0; printf ("0\n"); Break }} if (flag) printf ("1\n"); } return 0;}
HDU 1878 Euro-pull circuit