Problem
Test instructions
n a point that represents ABC three characters, A and b are connected, B and C are connected, the same is connected, and now give you n points and the M-bar between them, to determine if there is such a string, the existence of a matching condition.
Analysis
My approach is to find out all B, because B is just not connected to itself, so there is a n-1 connection, and then find out that the first is not a B, and then all and that point is not the connection is set to C, with a connection instead of B is set to a, and then set the point to a.
Next, according to the condition of the topic, judging the string I set out is not tenable. Is that if the connection is not the same letter or a B letter, and if the connection is a and C, it is not consistent.
Code
#include <stdio.h> #include <algorithm> #define F (A,B,C) for (int a=b;a<=c;a++) #define N 505using Namespace Std;int N,m,a[n][n],l[n],u,v,ans,ok;char s[n];int main () { scanf ("%d%d", &n,&m); F (i,1,m) { scanf ("%d%d", &u,&v); A[u][v]=a[v][u]=1; l[u]++; l[v]++; } F (I,1,n) if (l[i]==n-1) s[i]= ' B '; int i=1; while (s[i]== ' B ' &&i<=n) i++; F (J,1,n) if (!a[i][j]) s[j]= ' C '; else if (s[j]!= ' B ') s[j]= ' a '; S[i]= ' a '; F (I,1,n&&ok!=-1) f (j,i+1,n) if (!a[i][j]&& (s[i]==s[j]| | s[i]== ' B ') | | a[i][j]&& (s[i]== ' A ' &&s[j]== ' C ')) ok=-1; if (ok==-1) printf ("no\n"); else { printf ("yes\n"); F (j,1,n) printf ("%c", S[j]); } return 0;}
"Codeforces 624C" Graph and String