Http://codeforces.com/problemset/problem/272/E
Think of hatred as a side,
Because the degree can only be 0,1,2,3, so there are several
0,1 can be put directly
2: There are (in), (0,2) Two cases, the first kind of casually put, the second kind put 0 there
3: There are two cases, (0,3), the first kind puts 1, the second puts 0 there
In other words, there are solutions.
DFS Search can
But at first I felt this was not true, because the time is very complicated, but I never thought of it.
#include <cstdio> #include <vector>using namespace Std;const int Maxn=3e5+5;bool other[maxn];vector<int > E[maxn];int n,m;void Print () {for (int i=1;i<=n;i++) {if (Other[i]) printf ("1"); else printf ("0"); } puts ("");} void judge (int s) {int o=0; for (int i=0;i< (int) e[s].size (); i++) {int t=e[s][i]; if (Other[t]==other[s]) o++; } if (o>1) {other[s]=!other[s]; for (int i=0;i< (int) e[s].size (); i++) {int t=e[s][i]; if (Other[t]==other[s]) judge (T); }}}int Main () {scanf ("%d%d", &n,&m); for (int i=0;i<m;i++) {int f,t; scanf ("%d%d", &f,&t); E[f].push_back (t); E[t].push_back (f); } for (int i=1;i<=n;i++) {judge (i); } print (); return 0;}
CF 272E Dima and Horses staining, DFS difficulty: 2