A8547 | Deputies
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
The Trinitarian kingdom has exactly $n=3k$ cities. All of them are located on the shores of river Trissisipi, which flows through the whole kingdom. Some of the cities are located on one side of the river, and all the rest are on the other side.
Some cities are connected by bridges built between them. Each bridge connects two cities that are located on the opposite sides of the river. Between any two cities exists no more than one bridge.
The recently inaugurated King Tristan the Third is busy distributing his deputies among cities. In total there are $k$ deputies and the king wants to commission each of them to control exactly three cities. However, no deputy can be entrusted to manage the cities, which are connected by a bridge — the deputy can set a too high fee for travelling over the bridge to benefit his pocket, which is bad for the reputation of the king.
Help King Tristan the Third distribute the deputies between the cities, if it is possible.
Some cities are connected by bridges built between them. Each bridge connects two cities that are located on the opposite sides of the river. Between any two cities exists no more than one bridge.
The recently inaugurated King Tristan the Third is busy distributing his deputies among cities. In total there are $k$ deputies and the king wants to commission each of them to control exactly three cities. However, no deputy can be entrusted to manage the cities, which are connected by a bridge — the deputy can set a too high fee for travelling over the bridge to benefit his pocket, which is bad for the reputation of the king.
Help King Tristan the Third distribute the deputies between the cities, if it is possible.
输入格式
The first line contains two integers $n$ and $m$ — the number of cities and bridges ( $3<=n<10^{5}$ , $n=3k$ , $0<=m<=10^{5}$ ). Next $m$ lines describe the bridges. The $i$ -th line contains two integers $a_{i}$ and $b_{i}$ — the numbers of cities that are connected by the $i$ -th bridge ( $1<=a_{i},b_{i}<=n$ , $a_{i}≠b_{i}$ , $1<=i<=m$ ).
It is guaranteed that no bridge connects a city with itself and that any two cities are connected with no more than one bridge.
It is guaranteed that no bridge connects a city with itself and that any two cities are connected with no more than one bridge.
输出格式
If distributing the deputies in the required manner is impossible, print in a single line "NO" (without the quotes).
Otherwise, in the first line print "YES" (without the quotes), and in the second line print which deputy should be put in charge of each city. The $i$ -th number should represent the number of the deputy (from $1$ to $k$ ), who should be in charge of city numbered $i$ -th in the input — overall there should be $n$ numbers.
If there are multiple solutions, print any of them.
Otherwise, in the first line print "YES" (without the quotes), and in the second line print which deputy should be put in charge of each city. The $i$ -th number should represent the number of the deputy (from $1$ to $k$ ), who should be in charge of city numbered $i$ -th in the input — overall there should be $n$ numbers.
If there are multiple solutions, print any of them.
输入输出样例
输入 #1
6 6 1 2 4 1 3 5 6 5 2 6 4 6
输出 #1
YES 1 2 1 2 2 1
输入 #2
3 1 1 2
输出 #2
NO
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted