Fzu 2112 Tickets

Source: Internet
Author: User

This problem can be changed, first of all to know that there are several connected blocks, connecting blocks must be added between a side,

You also need to know that each connected block needs to add several edges inside, this problem is equivalent to the need for a graph at least a few strokes, the answer to this question is the number of points of odd degrees/2

#include <cstdio>#include<cstring>#include<cmath>#include<vector>#include<algorithm>using namespacestd;Const intmaxn=100000+Ten;intT;intN,m;vector<int>G[MAXN];intTOT[MAXN];BOOLFLAG[MAXN];BOOLFLAG2[MAXN];intq[maxn],sum;intans;voidinit () {ans=0; memset (Tot,0,sizeoftot); memset (Flag,0,sizeofflag); memset (Flag2,0,sizeofflag2);}voidRead () {scanf ("%d%d",&n,&m);  for(intI=1; i<=n;i++) g[i].clear ();  for(intI=1; i<=m;i++)    {        intU,v; scanf"%d%d",&u,&v); Tot[u]++;tot[v]++; Flag2[u]=1; flag2[v]=1;        G[u].push_back (v);    G[v].push_back (U); }}voidDfsintNow ) {Flag[now]=1; q[sum++]=Now ;  for(intI=0; I<g[now].size (); i++)        if(!Flag[g[now][i]]) DFS (g[now][i]);}voidWork () { for(intI=1; i<=n;i++)    {        if(!flag[i]&&Flag2[i]) {Sum=0; ans++; Dfs (i); inttmp=0;  for(intj=0; j<sum;j++)if(tot[q[j]]%2==1) tmp++; Ans=ans+ (tmp-1)/2; }} ans--; printf ("%d\n", ans);}intMain () {scanf ("%d",&T);  while(t--) {init ();        Read ();    Work (); }    return 0;}

Fzu 2112 Tickets

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.