A10222 | Graph and String
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
One day student Vasya was sitting on a lecture and mentioned a string $s_{1}s_{2}...\ s_{n}$ , 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 $s_{i}$ and $s_{j}$ 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$ .
- $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 $s_{i}$ and $s_{j}$ 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$ .
输入格式
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 $u_{i}$ and $v_{i}$ $(1<=u_{i},v_{i}<=n,u_{i}≠v_{i})$ — 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.
Each of the next $m$ lines contains two integers $u_{i}$ and $v_{i}$ $(1<=u_{i},v_{i}<=n,u_{i}≠v_{i})$ — 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.
输出格式
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.
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.
输入输出样例
输入 #1
2 1 1 2
输出 #1
Yes aa
输入 #2
4 3 1 2 1 3 1 4
输出 #2
No
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.
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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted