Hdu1878 Euler's loop

Source: Internet
Author: User
1 // accepted 1240 kb 250 MS 2 // questions Euler loop 3 // connectivity + node degree are even 4 # include <cstdio> 5 # include <cstring> 6 # include <queue> 7 # include <iostream> 8 using namespace STD; 9 const int imax_n = 1005; 10 bool a [imax_n] [imax_n]; 11 bool vis [imax_n]; 12 int cnt [imax_n]; 13 int n, m; 14 queue <int> q; 15 16 void BFS (INT s) 17 {18 while (! Q. Empty () Q. Pop (); 19 q. Push (s); 20 vis [s] = true; 21 While (! Q. empty () 22 {23 int x = Q. front (); 24 Q. pop (); 25 for (INT I = 1; I <= N; I ++) 26 {27 if (! Vis [I] & A [x] [I] = true) 28 {29 vis [I] = true; 30 Q. push (I); 31} 32} 33} 34} 35 int judge () 36 {37 memset (VIS, 0, sizeof (VIS); 38 int ans = 0; 39 For (INT I = 1; I <= N; I ++) 40 {41 if (! Vis [I]) ans ++; 42 if (ANS> = 2) return 0; 43 BFS (I); 44} 45 return 1; 46} 47 int slove () 48 {49 // printf ("Judge = % d \ n", Judge (); 50 if (Judge () = 0) return 0; 51 for (INT I = 1; I <= N; I ++) 52 {53 If (CNT [I] % 2! = 0) return 0; 54} 55 return 1; 56} 57 int main () 58 {59 While (scanf ("% d", & N), n) 60 {61 scanf ("% d", & M); 62 memset (CNT, 0, sizeof (CNT); 63 memset (A, false, sizeof ()); 64 int X, Y; 65 for (INT I = 1; I <= m; I ++) 66 {67 scanf ("% d", & X, & Y); 68 A [x] [Y] = A [y] [x] = true; 69 CNT [x] ++; 70 CNT [y] ++; 71} 72 printf ("% d \ n", slove (); 73} 74 return 0; 75}
View code

 

Hdu1878 Euler's loop

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.