Hdu1878 Euler loop (Euler loop)

Source: Internet
Author: User
1. UNICOM. if the vertex degrees are even, there is an Euler loop. # Include # includeusingnamespacestd; intfather [1010]; intvis [1010] [1010], du [1010]; intfind (intx) {if (father [x] = x)
// 1. Unicom figure 2. if the vertex degrees are even, there is an Euler loop. # Include
 
  
# Include
  
   
Using namespace std; int father [1010]; int vis [1010] [1010], du [1010]; int find (int x) {if (father [x] = x) return x; return father [x] = find (father [x]);} int main () {int n, m, i, a, B, cot; while (~ Scanf ("% d", & n), n) {for (I = 1; I <= n; I ++) father [I] = I; scanf ("% d", & m); memset (vis, 0, sizeof (vis); memset (du, 0, sizeof (du); while (m --) {scanf ("% d", & a, & B); if (! Vis [a] [B]) {if (a> B) swap (a, B); // small front, ensure that the smallest vis [a] [B] = vis [B] [a] = 1; du [a] ++; du [B] ++; int fa = find (a); int fb = find (B); if (fa! = Fb) {father [fb] = fa ;}} cot = 0; for (I = 1; I <= n; I ++) {if (du [I] % 2 = 0 & find (I) = 1) {cot ++ ;}} if (cot = n) printf ("1 \ n"); else printf ("0 \ n");} return 0 ;}
  
 

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.