Test instructions: Give a graph, ask at least how many edges can connect a singular circle, also require the output of the method of the number of edges.
Ideas: Game time to look at the picture is related to not much thought, there is no time, in fact, quite simple, if there is a strange circle, then the direct output 0 1, if there are two points connected, then is (n-2) XM, is each edge and another arbitrary point even two edges, or there is no edge, this is the direct output results.
A little bit of trouble is the last one, the Unicom block has a number of points and no odd circle, this time need to connect fast black and white dyeing, the same color point is a strange circle, DFS when the statistics of each unicom block two = the number of colors.
#include <bits/stdc++.h>#definePB Push_backusing namespaceStd;typedefLong Longll;Const intmaxv=1e5+ +; ll N,m;vector<int>G[maxv];ll CONT1[MAXV],CONT2[MAXV];BOOLVIS[MAXV];BOOLCOL[MAXV];intcontcomp=0;BOOLDfsintUBOOLc) { if(Vis[u]) {if(col[u]==c) { return false; }Else{ return true; } }Else{Vis[u]=1; BOOLflag=1; Col[u]=!C; ll*now= (!c?Cont1:cont2); Now[contcomp]++; for(intI=0; I<g[u].size (); i++) {flag&=dfs (g[u][i],!c); } returnFlag; }}intMain () {///freopen ("/home/files/cppfiles/in", "R", stdin);Cin>>n>>m; for(intI=0; i<m;i++){ intf,t; scanf ("%d%d",&f,&t); G[F].PB (t); G[T].PB (f); } if(m==0) {cout<<"3"<<n* (n1) * (n2)/6<<Endl; return 0; } BOOLflag=1; for(intI=1; i<=n;i++)if(G[i].size () >1) flag=0; if(flag) {cout<<"2"<< (n2) *m<<Endl; return 0; } for(intI=1; i<=n;i++){ if(!Vis[i]) {Contcomp++; if(!dfs (I,0) ) {cout<<"0 1"<<Endl; return 0; }}} ll ans=0; for(intI=1; i<=contcomp;i++) {ans+=cont1[i]* (cont1[i]-1)/2+cont2[i]* (cont2[i]-1)/2; } cout<<"1"<<ans<<Endl; return 0;}
View Code
Codeforces Round #311 (Div. 2)--d (figure