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