CF923F.Public Service
NOI/NOI+/CTSC
通过率:0%
时间限制:4.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There are N cities in Bob's country connected by roads. Some pairs of cities are connected by public transport. There are two competing transport companies — Boblines operating buses and Bobrail running trains. When traveling from A to B, a passenger always first selects the mode of transport (either bus or train), and then embarks on a journey. For every pair of cities, there are exactly two ways of how to travel between them without visiting any city more than once — one using only bus routes, and the second using only train routes. Furthermore, there is no pair of cities that is directly connected by both a bus route and a train route.
You obtained the plans of each of the networks. Unfortunately, each of the companies uses different names for the same cities. More precisely, the bus company numbers the cities using integers from 1 to N, while the train company uses integers between N + 1 and 2_N_. Find one possible mapping between those two numbering schemes, such that no pair of cities is connected directly by both a bus route and a train route. Note that this mapping has to map different cities to different cities.
Bob 的国家中有 N 座城市,由道路连接。其中某些城市对之间有公共交通连接。目前有两家相互竞争的交通公司:运营公交车的 Boblines 公司和运营火车的 Bobrail 公司。当乘客从城市 A 前往城市 B 时,总是先选择交通方式(公交或火车),再开始行程。对于任意一对城市,均恰好存在两种不重复经过任一城市的路径:一种仅使用公交线路,另一种仅使用铁路线路。此外,不存在任何一对城市同时被一条公交线路和一条铁路线路直接连接。
你已获取了这两家公司的交通网络规划图。但不幸的是,两家公司对同一座城市采用了不同的命名方式:更准确地说,公交公司用 1 到 N 的整数为城市编号,而铁路公司则用 N+1 到 2N 的整数为城市编号。请找出一种可能的城市编号映射方案,使得没有任何一对城市被公交线路和铁路线路同时直接连接。注意,该映射必须是一一对应的(即不同城市映射到不同城市)。
输入格式
The first line contains an integer N (2 ≤ N ≤ 10000), the number of cities.
N - 1 lines follow, representing the network plan of Boblines. Each contains two integers u and v (1 ≤ u, v ≤ N), meaning that there is a bus route between cities u and v.
N - 1 lines follow, representing the network plan of Bobrail. Each contains two integers u and v (N + 1 ≤ u, v ≤ 2_N_), meaning that there is a train route between cities u and v.
第一行包含一个整数 N(2≤N≤10000),表示城市的数量。
接下来的 N−1 行表示 Boblines 的网络规划。每行包含两个整数 u 和 v(1≤u,v≤N),表示城市 u 与城市 v 之间有一条公交线路。
再接下来的 N−1 行表示 Bobrail 的网络规划。每行包含两个整数 u 和 v(N+1≤u,v≤2N),表示城市 u 与城市 v 之间有一条铁路线路。
输出格式
If there is no solution, output a single line with the word "No".
If a solution exists, output two lines. On the first line, there should be the word "Yes". On the second line, there should be N integers _P_1, P_2, ..., P__N (N + 1 ≤ P__i ≤ 2_N) — the mapping between the two numbering schemes. More precisely, for i ≠ j it should be P__i ≠ P__j, and for every direct bus route (i, j), there is no direct train route between (P__i, P__j).
If there are multiple solutions, you may print any of them.
如果无解,输出一行单词“No”。
如果有解,输出两行。第一行输出单词“Yes”。第二行输出 N 个整数 P1,P2,...,PN(满足 N+1≤Pi≤2N),表示两种编号方案之间的映射关系。更准确地说,对任意 i=j,需满足 Pi=Pj;且对每一条直达公交线路 (i,j),在 (Pi,Pj) 之间不存在直达铁路线路。
若存在多个解,输出任意一个即可。
输入输出样例
输入#1
4 1 2 2 3 3 4 5 6 6 7 7 8
输出#1
Yes 6 8 5 7
输入#2
4 1 2 2 3 3 4 5 6 5 7 5 8
输出#2
No
输入#3
7 1 2 1 3 1 4 1 5 5 6 6 7 8 9 9 10 10 11 11 12 12 13 13 14
输出#3
Yes 9 14 11 12 13 10 8
说明/提示
The first sample (bus lines in red and rail lines in blue):

第一个样例(红色为公交线路,蓝色为铁路线路):

输入解题思路,AI测评打分。不知道怎么写?