C. Graph and String

Source: Internet
Author: User

Two-part graph dyeing

b point with all except the point of their own connection, a total of n-1, first connect n-1 points all set to B, the other points any point set to a, and a is connected to a point, the remaining is the C point. The final verification is true.

The validation condition is that the absolute value of the difference between all connected points does not exceed 1, and the absolute value of the difference between the disconnected points is greater than 1.

1#include <bits/stdc++.h>2#include <stdlib.h>3#include <math.h>4 using namespacestd;5 intmp[520][520];6 intcnt[520];7 intflag[520];8 intn,m;9 intMain ()Ten { Onescanf"%d%d",&n,&m); A  -      for(intI=1; i<=m;i++) -     { the         intx, y; -scanf"%d%d",&x,&y); -mp[x][y]=mp[y][x]=1; -cnt[x]++; +cnt[y]++; -     } +      for(intI=1; i<=n;i++) A     { at         if(cnt[i]==n-1) -flag[i]=2; -  -     } -     intnow=0; -      for(intI=1; i<=n;i++) in     { -         if(flag[i]!=2) to         { +now=i; -              Break; the         } *     } $         if(now==0)Panax Notoginseng         { -printf"yes\n"); the              for(intI=1; i<=n;i++) +printf"b"); A             return 0; the         } +  -flag[now]=1; $          for(intI=1; i<=n;i++) $         { -             if(now==i)Continue; -            //if (Mp[i][now]) the             if(!mp[i][now]) flag[i]=3; -             Else if(flag[i]==0) flag[i]=1;Wuyi         } the          for(intI=1; i<=n;i++) -         { Wu              for(intj=1; j<=n;j++) -             { About                 if(I==J)Continue; $                 if(Mp[i][j]) -                 { -                     if(ABS (FLAG[I]-FLAG[J]) >1) -                         returnPuts"No"); A                 } +                 Else the                 { -                     if(ABS (Flag[i]-flag[j]) <=1) $                         returnPuts"No"); the                 } the             } the         } theprintf"yes\n"); -          for(intI=1; i<=n;i++) in         { the             if(flag[i]==1) cout<<'a'; the             Else if(flag[i]==2) cout<<'b'; About             Elsecout<<'C'; the         } the         return 0; the  +}

C. Graph and String

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.