"Codeforces 624C" Graph and String

Source: Internet
Author: User

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

Related Article

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.