Hihocoder 1181 Euro-La Road. Two

Source: Internet
Author: User

Portal: Oralu Shi

#1181: Oralu Shi

Time limit:10000msSingle Point time limit:1000msMemory Limit:256MBDescription in the previous back small hi and small ho control the protagonist gathered on the various wooden bridge props, these props are actually a piece of dominoes. The protagonist continued to move forward, a stone bridge appeared in front of the stone bridge at the end of a fire wall, it seems unable to pass. Little Hi noticed that there was a small piece of paper at the bridge, so the controlling protagonist picked up the paper, and saw it read:
The flame wall can be closed by placing the M-block dominoes in the concave of the stone bridge. Remember that dominoes need the same number to connect. --by unknown adventurer.
Small hi and Small ho opened the main character of the props bar, found that the protagonist happens to have M fast Domino. Small ho: That means to put all the dominoes in the groove to close the flame wall, what does the number mean? Little hi: You see, each piece of dominoes has a number, probably only when the number is the same can be placed, for example: small ho: So, let's see if we can connect all the dominoes. Tip: Fleury algorithm to find Euler path input line 1th: 2 positive integers, n,m. Indicates the maximum number and number of dominoes that appear on the dominoes, respectively. 1≤n≤1,000,1≤m≤5,000 2nd. M+1 lines: 2 integers per line, u,v. Line I+1 represents the number at both ends of the block I (U,V), 1≤u,v≤n outputs the 1th line: m+1 number, indicating the number of dominoes connected after the end of the figure, such as the state of the Domino connection is (1,5) (5,3) (3,2) (2,4) (4,3), then output "1 5 3 2 4 3" You can output any set of legitimate solutions.
Sample Input
5 53 53 24 23 45 1
Sample Output
1 5 3 4 2 3

The main point of this problem is how to achieve the deletion , a kind of the implementation of an array of pro-table (can replace the vector<int>) slightly modified can be.

1 structedge{2   intTo , Prev, next;3 };4Edge e[max_e<<1];//Error-prone5 intpath[max_e<<1];6 intPos[max_v], size[max_v];7 intpath_size;8 voidAdd_edge (int&id,intUintv) {9e[id].to=v;Tene[pos[u]].next=ID; Onee[id].prev=Pos[u]; Ae[id].next=-1; -pos[u]=id++; -size[u]++; the } - voidGet_graph (intE) { -   intId=0; -   intu, v; +    while(e--){ -scanf"%d%d", &u, &v); + Add_edge (ID, u, v); A Add_edge (ID, V, u); at   } - } - voidMove_edge (intUintNow ) { -   int&pre=E[now].prev; -   if(~pre) { -e[pre].next=E[now].next; in   } -   int&nt=E[now].next; to   if(~NT) { +e[nt].prev=E[now].prev; -   } the   Else{ *pos[u]=E[now].prev; $   }Panax Notoginseng}

We see that implementing a delete is just a matter of adding a next field (domain).

Note: The Get_graph function in the above code should contain the following initialization

memset (POS,-1sizeof0sizeof(size));

I wrote it in Main (), which is indispensable.

Full code:

1#include <bits/stdc++.h>2 #defineSet1 (a) memset (a,-1, sizeof (a))3 #defineSet0 (a) memset (a, 0, sizeof (a))4 using namespacestd;5 Const intmax_v=1e3+Ten, max_e=5e3+Ten;6 structedge{7   intTo , Prev, next;8 };9Edge e[max_e<<1];//Error-proneTen intpath[max_e<<1]; One intPos[max_v], size[max_v]; A intpath_size; - voidAdd_edge (int&id,intUintv) { -e[id].to=v; thee[pos[u]].next=ID; -e[id].prev=Pos[u]; -e[id].next=-1; -pos[u]=id++; +size[u]++; - } +  A voidGet_graph (intE) { at   intId=0; -   intu, v; -    while(e--){ -scanf"%d%d", &u, &v); - Add_edge (ID, u, v); - Add_edge (ID, V, u); in   } - } to voidMove_edge (intUintNow ) { +   int&pre=E[now].prev; -   if(~pre) { thee[pre].next=E[now].next; *   } $   int&nt=E[now].next;Panax Notoginseng   if(~NT) { -e[nt].prev=E[now].prev; the   } +   Else{ Apos[u]=E[now].prev; the   } + } - voidDfsintu) { $   intNow ; $    while(Now=pos[u], ~now) {//Error-prone -     int&v=e[now].to; - Move_edge (U, now); theMove_edge (V, now^1); - Dfs (v);Wuyi   } thepath[path_size++]=u; - } Wu intMain () { -Freopen ("inch","R", stdin); About   intV, E; $scanf"%d%d", &v, &E); - Set1 (POS); - set0 (size); - get_graph (E); APath_size=0; +   intbeg=1; the    for(intI=1; i<=v; i++){ -     if(size[i]&1){ $beg=i; the        Break; the     } the   } the dfs (beg); -    for(intI=0; i<path_size; i++){ inprintf"%d", Path[i]); the   } thePuts""); About   return 0; the}
Please pay special attention to how lines 48th and 49 are deleted. We can see that this kind of critical table implemented by arrays is more flexible and practical.

Hihocoder 1181 Euro-La Road. Two

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.