CF 272E Dima and Horses staining, DFS difficulty: 2

Source: Internet
Author: User

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

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.