Title Link: Hiho 50th week
Thought: Hiho already said very well, I will not interrupt.
Tip: Because the same side of the same edge with the opposite phase of the number similar, such as (u-v) positive Edge U->v label is 0, the reverse Edge v->u label is 1, and 0 or 1 divided by 2 is equal to 0, so no matter the positive and negative side of the building, as long as the access to any side of the forward reverse can be used head[u]/ 2 mark the original side as Vis=1 operation
/************************************************************** Problem:hiho User:youmi language:c++ Re sult:accepted time:3ms memory:0mb****************************************************************///#pragma COMMENT (linker, "/stack:1024000000,1024000000")//#include <bits/stdc++.h>#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<map>#include<stack>#include<sstream>#include<cmath>#include<queue>#include<string>#include<vector>#defineZeros (a) memset (A,0,sizeof (a))#defineOnes (a) memset (A,-1,sizeof (a))#defineSC (a) scanf ("%d", &a)#defineSC2 (A, b) scanf ("%d%d", &a,&b)#defineRep0 (i,n) for (int i=0;i<n;i++)#defineREP1 (i,n) for (int i=1;i<=n;i++)#definePT (a) printf ("%d\n", a)#defineLson (step<<1)#defineRson (lson+1)#defineESP 1e-6#defineOO 0x3fffffff#defineTEST cout<< "*************************" <<endlusing namespaceStd;typedefLong Longll;intn,m;Const intmaxn= ++Ten;Const intmaxm= the+Ten;inthead[maxn],euler[maxm],vis[maxn],deg[maxm<<1];//because the output m+1 points, the size of Euler should be MAXMinttot,t;structside{intV,next;} E[MAXM<<1];voidBuildintUintv) {E[T].V=v; E[t].next=Head[u]; Head[u]=t++;}voidinit () {tot=0; T=0; Ones (head); Zeros (VIS); Zeros (deg);}voidDfsintu) { //pt (u); while(head[u]!=-1) { intv=e[head[u]].v; if(!vis[head[u]/2]) {Vis[head[u]/2]=1;//Mark No-edge u-v access to DFS (v); } Head[u]=e[head[u]].next;//Delete operation} euler[++tot]=u;//record Euler path}intMain () {//freopen ("In.txt", "R", stdin); while(~SC2 (n,m)) {init (); intu,v; while(m--) {SC2 (u,v); Build (U,V); Build (V,u); Deg[u]++; DEG[V]++; } intflag=1; REP1 (I,n)//Look for odd points, if all are even, then randomly from which point to start Dfs is the same {if(deg[i]%2) {flag=i; Break; }} DFS (flag); REP1 (I,tot) {printf ("%d", Euler[i]); } printf ("\ n");//In fact, this sentence is the same, the output requirements are quite loose } return 0;}
Fleury algorithm to find Euler path Hiho 50th Week