Codeforces Round #311 (Div. 2) D. Vitaly and Cycle (two-figure dyeing, singular ring)

Source: Internet
Author: User

Given n points, M-bar edges.

The minimum number of edges required to make the odd ring in the diagram, and the output of the method of adding edges at this time

According to test instructions, it is only possible to

0: The odd ring already exists, DFS has been dyed and the color is the same

1: Determine the number of stained black and white in each connected block

2: The degree of a point > 1

3:0 Sides

1#include <cstdio>2#include <iostream>3#include <queue>4#include <vector>5#include <stack>6#include <Set>7#include <string>8#include <cstring>9#include <math.h>Ten#include <algorithm> One#include <map> A  -#include <sstream> -#include <ctype.h> the  - #defineLson l,m,rt<<1 - #defineRson m+1,r,rt<<1|1 -   +typedefLong Longll; - using namespacestd; +   A Const intINF =0x7f7f7f7f; at Const DoublePI = ACOs (-1.0); - Const intMAXN =1005; - Const intMOD = (int) 1e9+7; - #defineLOCAL 0 - #defineMOD 1000000007 -  in  - /* to 0 Sides: 0 1 + 1 Sides: - 2-side m* (n-2) the 3 side Cn3 * */ $ intn,m;Panax Notoginseng intdegree[100005]; -vector<int> g[100005]; the intcolor[100005]; + intw[100005],b[100005];  A BOOLf,f0; the intCnt//several unicom blocks + voidDfsintUintCintnum) { -Color[u] =C; $     if(C &1) w[num]++; $     Elseb[num]++; -      -      for(inti =0; I < g[u].size (); i + +){ the         intv =G[u][i]; -         if(!Color[v]) {WuyiDFS (V,3-c,num); the}Else{ -             if(Color[u] = =Color[v]) { WuF0 =true; -             } About         } $     } - } -  - voidsolve () { A     //3 sides +     if(M = =0){ theprintf"%d%i64d\n",3, 1ll*n* (n1) * (n2)/6); -         return ; $     } the      for(inti =0; I <= N; i + +) g[i].clear (); thememset (Degree,0,sizeof(degree)); thef =true; the      for(inti =0; I < m; i + +){ -         intu,v; inscanf"%d%d",&u,&v); theG[u].push_back (v); degree[u]++; theG[v].push_back (U); degree[v]++; About         if((Degree[u) >1) || (Degree[v] >1)) F =false; the     } the     //2 sides the     if(f) { +printf"2%i64d\n", 1ll*m* (n2)); -         return ; the     }  Bayi      theF0 =false; theCNT =0; -memset (Color,0,sizeof(color)); -Memset (W,0,sizeof(w)); thememset (b,0,sizeof(b)); the      for(inti =1; I <= N; i + +){ the         if(!Color[i]) theDFS (I,1, cnt++); -     } the      the     //0 Sides the     if(F0) {94printf"0 1\n"); the         return; the     } the     98     //1 Sides Aboutll ans =0;  -      for(inti =0; I < CNT; i + +){101Ans = ans + 1ll*w[i]* (w[i]-1)/2+ 1ll*b[i]* (b[i]-1)/2;102     }103printf"1%i64d\n", ans);104     return ; the }106 intMain () {107     108      while(SCANF ("%d%d", &n,&m)! =EOF) {109 solve (); the     }111      the     return 0;113}

Codeforces Round #311 (Div. 2) D. Vitaly and Cycle (two-figure dyeing, singular ring)

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.