Uvaoj10054-The neck.pdf

Source: Internet
Author: User

1/* 2 Question: print the Euler loop! 3. Why is DFS a post-sequential traversal? 4 because the Euler Loop itself is a loop, we may find a loop in advance during DFS. This loop may not be an Euler loop. 5 because it has not traversed all the sides! If it is written as a forward traversal, the stored path is not a complete path! It may consist of multiple circuits! The answer is wrong! If it is post-sequential traversal, when DFS encounters a loop, it will exit the search of the current stack! 7. Search for other paths! Only one loop path is obtained! --> Euler Loop ~! 8 */9 # include <iostream> 10 # include <cstring> 11 # define M 5512 # define Max 0x3f3f3f13 using namespace STD; 14 15 int CNT [m] [m]; 16 int deg [m]; 17 int map [m] [m]; 18 int X; 19 20 struct point {21 int X, Y; 22 point () {} 23 24 point (int x, int y) {25 this-> X = x; 26 This-> Y = y; 27} 28 }; 29 30 point P [1005]; 31 int top; 32 33 void DFS (int u) {34 if (! DEG [u]) return; 35 for (INT I = 1; I <= 50; ++ I) 36 IF (Map [u] [I] & CNT [u] [I]) {37 -- CNT [u] [I]; 38 -- CNT [I] [u]; 39 -- deg [u]; 40 -- deg [I]; 41 DFS (I ); 42 p [++ top] = point (u, I); 43} 44} 45 46 int main () {47 int t, n, k = 0; 48 CIN> T; 49 while (t --) {50 CIN> N; 51 X = max; 52 memset (CNT, 0, sizeof (CNT )); 53 memset (MAP, 0, sizeof (MAP); 54 memset (deg, 0, sizeof (DEG); 55 for (INT I = 1; I <= N; ++ I) {56 int U, V; 57 CIN> U> V; 58 deg [u] ++; 59 deg [v] ++; 60 map [u] [v] = 1; 61 map [v] [u] = 1; 62 CNT [u] [v] ++; 63 CNT [v] [u] ++; 64 if (x> U) x = u; 65 if (x> V) X = V; 66} 67 int OK = 0; 68 for (INT I = 1; I <= 50; ++ I) 69 If (deg [I] % 2! = 0) {70 OK = 1; 71 break; 72} 73 cout <"case #" <+ + k <Endl; 74 if (OK) {75 cout <"some beads may be lost" <Endl; 76 if (t) cout <Endl; 77 continue; 78} 79 Top = 0; 80 DFS (x); 81 If (Top = N) {82 For (top; top> = 1; -- top) 83 cout <p [Top]. x <"" <p [Top]. Y <Endl; 84} 85 else cout <"some beads may be lost" <Endl; 86 If (t) cout <Endl; 87} 88 return 0; 89}

 

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.