HDU 3018 Ant Trip (Euler path)

Source: Internet
Author: User

Title Address: HDU 3018

For each point, the number of degrees is odd for each connected branch, and then the number of times required is number/2. Note that the isolated points cannot be counted.

The code is as follows:

#include <iostream> #include <string.h> #include <math.h> #include <queue> #include < algorithm> #include <stdlib.h> #include <map> #include <set> #include <stdio.h>using namespace std; #define LL Long long#define pi ACOs ( -1.0) const int Mod=1e9+7;const int Inf=0x3f3f3f3f;const double eqs=1e-9; const int Maxn=100000+10;int HEAD[MAXN], CNT, VIS[MAXN], DEG[MAXN], sum, ans;struct node{int i, V, next;}        edge[4*maxn];void Add (int u, int v) {edge[cnt].v=v;        Edge[cnt].next=head[u]; head[u]=cnt++;}        void Dfs (int u) {if (deg[u]&1) sum++;                for (int i=head[u];i!=-1;i=edge[i].next) {int v=edge[i].v;                        if (!vis[v]) {vis[v]=1;                DFS (v);        }}}void init () {memset (head,-1,sizeof (head));        cnt=0;        memset (vis,0,sizeof (VIS));        memset (deg,0,sizeof (deg)); Ans=0;}     int main () {int n, m, I, J, u, V;   while (scanf ("%d%d", &n,&m)!=eof) {init ();                        while (m--) {scanf ("%d%d", &u,&v);                        if (u==v) continue;                        Add (U,V);                        Add (V,u);                deg[u]++;d eg[v]++; } for (i=1;i<=n;i++) {if (!vis[i]&&[i]) {sum                                = 0;                                DFS (i);                                if (sum) ANS+=SUM/2;                        else ans+=1;        }} printf ("%d\n", ans); } return 0;}


HDU 3018 Ant Trip (Euler path)

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.