40,192 Division Chart Determination |
Difficulty level: B; programming language: Unlimited; run time limit: 1000ms; run space limit: 51200KB; code length limit: 2000000B |
Question Description |
Given a graph with n vertices (vertex numbered 0,1,......,n-1), dye each vertex on the graph and make the adjacent vertex colors different. Q. Can I dye it in up to 2 colors? The test data guarantees no heavy edges and self-loops. |
Input |
The first line consists of two numbers n and K, each representing the number of vertices and sides of the graph, followed by a K-line, with two integers m1 and m2 in each row, representing a non-lateral edge between the vertices M1 and M2. The integers of each row are separated by a single space. |
Output |
If it can output 1, otherwise output 0. |
Input example |
3 3 0 1 0 2 1 2
|
Output example |
0 |
Other Notes |
Data range: 1<=n<=1000, found to guess the answer to the brush question on the seal number. |
The puzzle: Dye a color. I remember you can use LCT dynamic maintenance of the two-part diagram unfortunately I forgot qaq ...
1#include <iostream>2#include <cstdio>3#include <cmath>4#include <algorithm>5#include <queue>6#include <cstring>7 #definePAU Putchar (")8 #defineENT Putchar (' \ n ')9 using namespacestd;Ten Const intmaxn= ++Ten, inf=-1u>>1; One structted{intX,Y;TED*NXT;} adj[maxn<<1],*fch[maxn],*ms=adj; A voidAddintXinty) { -*ms= (Ted) {x,y,fch[x]};fch[x]=ms++;*ms= (Ted) {y,x,fch[y]};fch[y]=ms++;return; - } the BOOLCOL[MAXN]; - BOOLColorintx) { - for(ted*e=fch[x];e;e=e->NXT) { - intV=e->y; + if(!col[v]) {col[v]=!col[x];if(!color (v))return false;} - Else if(Col[v]==col[x])return false; +}return true; A } atInlineintRead () { - intx=0, sig=1;CharCh=GetChar (); - for(;! IsDigit (CH); Ch=getchar ())if(ch=='-') sig=0; - for(; isdigit (ch); Ch=getchar ()) x=Ten*x+ch-'0'; - returnsig?x:-x; - } inInlinevoidWriteintx) { - if(x==0) {Putchar ('0');return;}if(x<0) Putchar ('-'), x=-x; to intlen=0, buf[ the]; while(x) buf[len++]=x%Ten, x/=Ten; + for(inti=len-1; i>=0; i--) Putchar (buf[i]+'0');return; - } the intn,m; * voidinit () { $N=read (); m=read ();Panax Notoginseng for(intI=1; i<=m;i++) Add (read (), read ()); - return; the } + voidWork () { Acol[0]=1;p UTS (Color (0)?"1":"0"); the return; + } - voidprint () { $ return; $ } - intMain () {init (); work ();p rint ();return 0;}
Coj 0578 40,192-point Figure determination