C. Graph and String
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

One day student Vasya was sitting on a lecture and mentioned a string s1s2... sn, consisting of letters "a", "b" and "c" that was written on his desk. As the lecture was boring, Vasya decided to complete the picture by composing a graph G with the following properties:

  • G has exactly n vertices, numbered from 1 to n.
  • For all pairs of vertices i and j, where i ≠ j, there is an edge connecting them if and only if characters si and sj are either equal or neighbouring in the alphabet. That is, letters in pairs "a"-"b" and "b"-"c" are neighbouring, while letters "a"-"c" are not.

Vasya painted the resulting graph near the string and then erased the string. Next day Vasya's friend Petya came to a lecture and found some graph at his desk. He had heard of Vasya's adventure and now he wants to find out whether it could be the original graph G, painted by Vasya. In order to verify this, Petya needs to know whether there exists a string s, such that if Vasya used this s he would produce the given graph G.

Input

The first line of the input contains two integers n and m  — the number of vertices and edges in the graph found by Petya, respectively.

Each of the next m lines contains two integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi) — the edges of the graph G. It is guaranteed, that there are no multiple edges, that is any pair of vertexes appear in this list no more than once.

Output

In the first line print "Yes" (without the quotes), if the string s Petya is interested in really exists and "No" (without the quotes) otherwise.

If the string s exists, then print it on the second line of the output. The length of s must be exactly n, it must consist of only letters "a", "b" and "c" only, and the graph built using this string must coincide with G. If there are multiple possible answers, you may print any of them.

Sample test(s)
input
2 1
1 2
output
Yes
aa
input
4 3
1 2
1 3
1 4
output
No
Note

In the first sample you are given a graph made of two vertices with an edge between them. So, these vertices can correspond to both the same and adjacent letters. Any of the following strings "aa", "ab", "ba", "bb", "bc", "cb", "cc" meets the graph's conditions.

In the second sample the first vertex is connected to all three other vertices, but these three vertices are not connected with each other. That means that they must correspond to distinct letters that are not adjacent, but that is impossible as there are only two such letters: a and c.

题意:给你n个点,和m条边,并且每个点只有三种选择,abc,如果两个字母是相等或相邻则表示他们 之间是有一条边,要你从他给你的边中,找一个符合要求的字母组合。

思路:贪心,假如给你一个点他与所有的顶点都有一条边,你会从,abc中你会取哪个字母,如果存在这样的点,你选a的话,就表示取余的点中不可能有c,同理选c也一样。

所以我们会选b,那么剩下那些未确定的点只有两种可能,a c,那么只要找一个未确定的点,给他a,那么与他有边的点肯定是a,无边的点是c,最后从的得到的字串判断下符合

要求即可。

 1 #include<stdio.h> 2 #include<algorithm> 3 #include<iostream> 4 #include<string.h> 5 #include<stdlib.h> 6 #include<vector> 7 #include<queue> 8 using namespace std; 9 void bi(int x,int y);10 vector<int>my[600];11 queue<int>que;12 char aa[600];13 bool flag[600][600];14 int check(int p);15 int main(void)16 {17     int n,i,j,k,p,q;18     while(scanf("%d %d",&p,&q)!=EOF)19     {20         for(i=0; i<600; i++)21         {22             my[i].clear();23         }24         memset(aa,0,sizeof(aa));25         memset(flag,0,sizeof(flag));26         int xx,yy;27         for(i=0; i<q; i++)28         {29             scanf("%d %d",&xx,&yy);30             flag[xx][yy]=true;31             flag[yy][xx]=true;32             my[xx].push_back(yy);33             my[yy].push_back(xx);34         }35         for(i=1;i<=p;i++)36         {37             if(my[i].size()==p-1)38             {39                 aa[i]='b';40             }41         }42         for(i=1;i<=p;i++)43         {44             if(aa[i]=='\0')45             {46              break;47             }48         }49         aa[i]='a';int cc=i;50         if(cc!=p+1)51         {for(i=1;i<=p;i++)52         {53             if(flag[cc][i]&&aa[i]=='\0')54             {55                 aa[i]='a';56             }57             else if(aa[i]=='\0')58             {59                 aa[i]='c';60             }61         }}if(check(p)==1)62         {printf("Yes\n");63             for(i=1;i<=p;i++)64                 printf("%c",aa[i]);65             printf("\n");66         }67         else printf("No\n");68     }return 0;69 }70 71 int check(int p)72 {73     int i,j,k,q;74     for(i=1;i<=p;i++)75     {76         for(j=i+1;j<=p;j++)77         {78             if((abs(aa[i]-aa[j])<=1&&!flag[i][j])||(abs(aa[i]-aa[j])==2&&flag[i][j]))79             {80                 return 0;81             }82         }83     }84     return 1;

85 }

codeforces 624C Graph and String的更多相关文章

  1. codeforces 623A. Graph and String 构造

    题目链接 给出一个图, 每个节点只有三种情况, a,b, c. a能和a, b连边, b能和a, b, c,连边, c能和b, c连边, 且无重边以及自环.给出初始的连边情况, 判断这个图是否满足条件 ...

  2. [Codeforces 623A] Graph and String

    [题目链接] http://codeforces.com/contest/623/problem/A [算法] 首先 , 所有与其他节点都有连边的节点需标号为'b' 然后 , 我们任选一个节点 , 将 ...

  3. AIM Tech Round (Div. 2) C. Graph and String 二分图染色

    C. Graph and String 题目连接: http://codeforces.com/contest/624/problem/C Description One day student Va ...

  4. 图论:(Code Forces) Graph and String

    Graph and String time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  5. Codeforces #541 (Div2) - E. String Multiplication(动态规划)

    Problem   Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...

  6. AIM Tech Round (Div. 2) C. Graph and String

    C. Graph and String time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  7. 【CodeForces 624C】Graph and String

    题 题意 n个表示abc三个字符的点,所有a和b是相连的,所有b和c是相连的,所有相同的是相连的,现在给你n个点和他们之间的m条边,判断是否存在这样的字符串,存在则给出一个符合条件的. 分析 我的做法 ...

  8. 【动态规划】【最短路】Codeforces 710E Generate a String

    题目链接: http://codeforces.com/problemset/problem/710/E 题目大意: 问写N个字符的最小花费,写一个字符或者删除一个字符花费A,将当前的字符数量翻倍花费 ...

  9. codeforces 632C The Smallest String Concatenation

    The Smallest String Concatenation 题目链接:http://codeforces.com/problemset/problem/632/C ——每天在线,欢迎留言谈论. ...

随机推荐

  1. 打造基于 PostgreSQL/openGauss 的分布式数据库解决方案

    在 MySQL ShardingSphere-Proxy 逐渐成熟并被广泛采用的同时,ShardingSphere 团队也在 PostgreSQL ShardingSphere-Proxy 上持续发力 ...

  2. C#表格,表格信息、GridView使用。

    page: <%@ Control Language="C#" AutoEventWireup="true" CodeFile="test1.a ...

  3. keras房价预测数据集boston_housing.npz文件下载

    github地址: https://github.com/yuxiwang66/boston_housing 码云地址: https://gitee.com/polarisslk/boston_hou ...

  4. 巩固java第七天

    巩固内容: HTML 属性 属性是 HTML 元素提供的附加信息. HTML 属性 HTML 元素可以设置属性 属性可以在元素中添加附加信息 属性一般描述于开始标签 属性总是以名称/值对的形式出现,比 ...

  5. Scala【json字符串和json对象互相转换】

    一.fastjson工具 pom依赖 <dependency> <groupId>com.alibaba</groupId> <artifactId>f ...

  6. [PE结构]导出表结构浅析

    导出函数的总数-->以导出函数序号最大的减最小的+1,但导出函数序号是可自定义的,所以NumbersOfFunctions是不准确的 1.根据函数名称找,函数名称表->对应索引函数序号表中 ...

  7. 【STM32】基于正点原子『探索者』开发板的烧录

    项目需要一个功能,开发板范例正好有,就买了一块,不过还是有点贵 我手边没有J-Link 用的都是串口烧录 烧录时,先打开右上的开关 如果是仿真器烧录,它无法供电,需要接12V适配器或是杜邦线供电 然后 ...

  8. Rest使用get还是post

    1. get是从服务器上获取数据,post是向服务器传送数据. 2. get是把参数数据队列加到提交表单的ACTION属性所指的URL中,值和表单内各个字段一一对应,在URL中可以看到.post是通过 ...

  9. Gitlab安装操作说明书

    一.Gitlab安装操作步骤 登录官方网站https://about.gitlab.com/downloads/根据你所需要的系统版本,作者使用的是centos6, 检查您的服务器是否符合硬件要求.g ...

  10. Javaj基础知识runtime error

    遇到的java 运行时错误: NullPointerException空指针  ,简单地说就是调用了未经初始化的对象或者是不存在的对象,这个错误经常出现在创建图片,调用数组这些操作中,比如图片未经初始 ...