CF1804E.Routing
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Ada operates a network that consists of n servers and m direct connections between them. Each direct connection between a pair of distinct servers allows bidirectional transmission of information between these two servers. Ada knows that these m direct connections allow to directly or indirectly transmit information between any two servers in this network. We say that server v is a neighbor of server u if there exists a direct connection between these two servers.
Ada needs to configure her network's WRP (Weird Routing Protocol). For each server u she needs to select exactly one of its neighbors as an auxiliary server a(u). After all a(u) are set, routing works as follows. Suppose server u wants to find a path to server v (different from u).
- Server u checks all of its direct connections to other servers. If it sees a direct connection with server v, it knows the path and the process terminates.
- If the path was not found at the first step, server u asks its auxiliary server a(u) to find the path.
- Auxiliary server a(u) follows this process starting from the first step.
- After a(u) finds the path, it returns it to u. Then server u constructs the resulting path as the direct connection between u and a(u) plus the path from a(u) to v.
As you can see, this procedure either produces a correct path and finishes or keeps running forever. Thus, it is critically important for Ada to configure her network's WRP properly.
Your goal is to assign an auxiliary server a(u) for each server u in the given network. Your assignment should make it possible to construct a path from any server u to any other server v using the aforementioned procedure. Or you should report that such an assignment doesn't exist.
Ada 运营着一个由 n 台服务器和它们之间的 m 条直接连接构成的网络。每条连接存在于两个不同的服务器之间,并允许这两个服务器之间双向传输信息。Ada 知道,这 m 条直接连接使得网络中任意两台服务器之间均可直接或间接地传输信息。若两台服务器 u 和 v 之间存在一条直接连接,则称服务器 v 是服务器 u 的邻居。
Ada 需要为其网络配置 WRP(奇异路由协议)。对于每台服务器 u,她必须恰好从其所有邻居中选定一台作为其辅助服务器 a(u)。在所有 a(u) 均设定完毕后,路由过程如下:假设服务器 u 想要找到一条通往服务器 v(v=u)的路径。
- 服务器 u 检查其与其余所有服务器之间的所有直接连接。若发现其中一条连接直接通向服务器 v,则它已知该路径,过程终止。
- 若第一步未找到路径,服务器 u 将请求其辅助服务器 a(u) 代为寻找该路径。
- 辅助服务器 a(u) 从第 1 步开始,依相同规则执行该过程。
- 当 a(u) 找到路径后,将该路径返回给 u;随后服务器 u 将自身与 a(u) 之间的直接连接,拼接在 a(u) 到 v 的路径之前,从而构造出最终路径。
如你所见,该过程要么生成一条正确的路径并终止,要么无限循环运行下去。因此,对 Ada 而言,正确配置 WRP 至关重要。
你的任务是:为给定网络中的每台服务器 u 分配一个辅助服务器 a(u),使得上述过程能成功构造出任意服务器 u 到任意其他服务器 v 的路径;或者判定这样的分配方案不存在。
输入格式
The first line of the input contains two integers n and m (2≤n≤20, n−1≤m≤2n⋅(n−1)) — the number of servers and the number of direct connections in the given network.
Then follow m lines containing two integers ui and vi (1≤ui,vi≤n, ui=vi) each, the i-th line describes the i-th direct connection.
It is guaranteed that there is no more than one direct connection between any two servers. It is guaranteed that there is a direct or indirect route (consisting only of the given direct connections) between any two servers.
输入的第一行包含两个整数 n 和 m(2≤n≤20,n−1≤m≤2n⋅(n−1)),分别表示服务器的数量以及给定网络中直接连接的数量。
接下来是 m 行,每行包含两个整数 ui 和 vi(1≤ui,vi≤n,ui=vi),第 i 行描述第 i 条直接连接。
保证任意两台服务器之间至多只存在一条直接连接。保证任意两台服务器之间均存在一条直接或间接路径(该路径仅由给定的直接连接构成)。
输出格式
If there is no way to assign an auxiliary server a(u) for each server u in such a way that WRP will be able to find a path from any server u to any other server v, print "No" in the only line of the output.
Otherwise, print "Yes" in the first line of the output. In the second line of the output print n integers, the i-th of these integers should be equal to a(i) – the index of the auxiliary server for server i. Do not forget that there must be a direct connection between server i and server a(i).
You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.
如果无法为每个服务器 u 分配一个辅助服务器 a(u),使得 WRP 能够找到从任意服务器 u 到任意其他服务器 v 的路径,则在输出的唯一一行中打印 "No"。
否则,在输出的第一行打印 "Yes";在输出的第二行打印 n 个整数,其中第 i 个整数应等于 a(i) —— 即服务器 i 的辅助服务器的编号。请注意,服务器 i 与服务器 a(i) 之间必须存在直接连接。
你可以以任意大小写形式输出答案(大写或小写均可)。例如,字符串 "yEs"、"yes"、"Yes" 和 "YES" 均会被识别为肯定回答。
输入输出样例
输入#1
6 7 1 2 2 3 3 1 4 5 5 6 4 6 2 5
输出#1
Yes 2 5 2 5 2 5
输入#2
3 2 1 2 2 3
输出#2
Yes 2 1 2
输入#3
4 4 1 3 2 3 4 1 4 2
输出#3
Yes 3 3 1 1
输入#4
6 5 1 2 2 3 3 4 4 5 5 6
输出#4
No
输入解题思路,AI测评打分。不知道怎么写?