CF 557D binary image black and white dyeing

Source: Internet
Author: User

Test instructions: Gives an n-point m-side graph, asking at least how many edges to make it possible to have odd rings, plus the number of cases with minimum edges

Odd rings and even rings are actually the properties of the bipartite graph: The bipartite graph does not exist in the singular ring, so just determine whether this picture is a bipartite graph on the line:

If it is not a binary map, then there must be an odd ring in the diagram, then there is no need to add edge, the number of cases is 1 species;

And if it is a common binary map, as long as there is a certain chunk of the number of points greater than or equal to 2, then as long as the same side of any two-point line, you can make it is not a binary map, resulting in odd ring, plus the number of 1, the number of cases is calculated how many half a bit greater than or equal to

If all is a two-point graph, it is necessary to a two-point graph, two points at the same time to any other point, you need to add 2 edges, the number of cases is two points of the number of units multiplied by the remaining points;

The last is a single point of the graph, must connect 3 lines, will be any three points 22 connected, the case number is any combination of three points.

1#include <stdio.h>2#include <string.h>3#include <algorithm>4 using namespacestd;5typedefLong Longll;6 7 intc[100005];8 intn,m,num[2];9 inthead[100005],nxt[200005],point[200005],size=0;Ten BOOLf=0; One  A voidAddintAintb) { -point[size]=b; -nxt[size]=Head[a]; thehead[a]=size++; -point[size]=A; -nxt[size]=Head[b]; -head[b]=size++; + } -  + voidDfsintAintx) { A     if(f)return; atc[a]=x; -num[x]++; -      for(intI=head[a];~i;i=Nxt[i]) { -         intb=Point[i]; -         if(c[b]==-1) DFS (b,!x); -         Else if(c[b]==x) { inf=1; -             return; to         } +     } - } the  * intMain () { $scanf"%d%d",&n,&m);Panax Notoginseng     if(m==0){ -ll ans= (LL) n (ll) (N-1) * (LL) (n2)/6; theprintf"3%i64d\n", ans); +         return 0; A     } the     inti; +memset (head,-1,sizeof(head)); -memset (c,-1,sizeof(c)); $      for(i=1; i<=m;i++){ $         intb; -scanf"%d%d",&a,&b); - Add (A, b); the     } -ll ans=0, ans2=0;Wuyi      for(i=1;i<=n&& (!f); i++){ the         if(c[i]==-1){ -num[0]=num[1]=0; WuDFS (I,1); -ans+= (LL) num[0]* (LL) (num[0]-1)/2; Aboutans+= (LL) num[1]* (LL) (num[1]-1)/2; $             if(num[0]==1&&num[1]==1){ -ans2+=n-2; -             } -         } A     } +     if(f) printf ("0 1\n"); the     Else if(ans==0) printf ("2%i64d\n", ans2); -     Elseprintf"1%i64d\n", ans); $     return 0; the}
View Code

CF 557D binary image black and white dyeing

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.