[Weird!] Euler Loop code implementation

Source: Internet
Author: User

ThisCodeThe process of finding a small Euler loop and concatenating them to form the Euler loop of the entire graph is realized. I have not figured out why it is correct ...... I think that loop is a key point.

// Read an undirected graph to determine the output loop # include <stdio. h> # define maxn 10010int BL [maxn] [maxn], Match [maxn], path [maxn * 2]; int tot, n, m, X, Y; bool can [maxn] [maxn]; bool check_map () {for (INT I = 1; I <= N; ++ I) if (Match [I] & 1) return 0; return 1;} void find_path (int x) {If (! Match [x]) {path [++ tot] = x; return;} For (INT I = 1; I <= bl [x] [0]; ++ I) {int K = bl [x] [I]; If ((! Match [k]) | (! Can [x] [k]) continue; -- match [X]; -- match [k]; can [x] [k] = Can [k] [x] = 0; find_path (k);} path [++ tot] = x;} int main () {freopen ("sample. in "," r ", stdin); freopen (" sample. out "," W ", stdout); scanf (" % d ", & N, & M); For (INT I = 1; I <= m; ++ I) {scanf ("% d", & X, & Y); BL [x] [++ BL [x] [0] = y; BL [y] [++ BL [y] [0] = x; ++ match [X]; ++ match [y]; can [x] [Y] = Can [y] [x] = 1;} If (! Check_map () {printf ("error! \ N "); Return 0;} find_path (1); For (INT I = 1; I <tot; ++ I) printf (" % D ----> ", path [I]); printf ("% d \ n", path [tot]); Return 0 ;}
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.