bzoj#P2267. Telephone Network
Telephone Network
题目描述
Telephone Network
A telephone company wants to build a new telephone network in a city.The company has the goal that each person in the city should be able to call each other person.Of course,it is not possible to build direct connections between every pair of persons.Instead,the company uses a network made up of several layers.
We denote a network switch in layer by .A switch consists of one input,one output and a cable connecting the input to the output.A switch with consists of inputs, outputs and two switches .
Input of () is connected via a cable to the inputs of each of the two switches .Similarly,output of is connected to the outputs of each of the two switches .
一个电话公司想在城市中搭建一个电话网络,他们的目标是让每两个人之间都能够通话。当然,在每两个用户之间直接搭一根电话线是不大可能的事情。于是公司采用了分层网络来解决这个问题。我们令第 层网络由开关 来控制。开关 包含一个输入,一个输出和一条将输入和输出连起来的电话线。开关 () 包含 个输入, 个输出和两个 级的开关。 的第 个输入是用线连接到 的 上。同样,输出也是这么连接的。
We are considering a network with one switch in the outermost layer.It can be shown that any input and output of switch has a unique connection path to any of the switches.Therefore,any input of can be connected to any of its outputs,and the connection path is uniquely determined by specifying through which switch the connection is established.
We number the switches belonging to the switch from to .The -th switch is defined as follows.Write the number in binary as .This defines a path from an input of to the -th switch via the following procedure:for each , indicates that the path extends from to the first switch to which it is directly connected,and indicates that the path extends to the second switch. Note that regardless of which input of is selected,this path arrives at the same switch,which is given the number .See also the figure below the sample data for details of how the numbering works.
Sometimes multiple connections are needed at the same time.In order to avoid interference,each of the inputs and outputs of all switches () can be used by at most one connection.Given a set of connection requests,can you find connection paths for each request such that the connection paths are disjoint?
最外层网络只有一个开关 。对已知 的任意一个输入和输出,他们都有一条独特的路径连接到 。因此,任意一个输入和输出就能够连接起来,而且这样的路径是独一无二的有连接到 的路径决定的。我们将 的 个 级开关标号为 ~。第 个开关的定义为:将 写成二进制 。 到 的路径是这么确定的:对于每一位 , 就表示 连接到第一个 开关,否则连接到第二个 开关。对于给定的 ,无论开关 的输入是什么,这个路径必须到达同一个 开关。不懂的就好好看样例。有时候多组连接必须同时使用,为了防止交叉干扰,每个开关只能在这些通话中使用一次。给你一些通话需求,你能找到满足所有要求且不相交的路径么?
输入格式
本题有多组数据
On the first line a positive integer:the number of test cases,at most .After that per test case:
One line with two integers and :the layer of the outermost switch and the number of connection requests.
lines,each with two integers and .Each such line represents a connection request from input number of to output number .You may assume that the integers are pairwise distinct,and the integers are pairwise distinct as well.
第一行一个正整数,表示测试数据,最多 组.
然后每一组包括:
第一个两个数 :网络的层数和连接需求数。
接下来 行,每行包括两个正整数 和 。表示输入和输出的编号。 和 只会出现一次。
输出格式
Per test case: One line with integers ,where is the number of the switch through which the connection of input to output is established.
The connection paths should be disjoint.You may print any valid solution,and you may assume that there is at least one valid solution.
Per test case:
个正整数 , 是 到 的连接路径
连接必须不相交。输出任意一个合法路径,并且路径是存在的。
2
1 1
0 1
3 5
0 3
1 4
2 5
3 6
4 7
0
3 0 1 2 4
样例解释 1
3 5 --- 层网络, 个连接
0 3
1 4
2 5
3 6
4 7
输入就这样了
输出
第一个
二进制表示为
表示 先连最外层的第一个开关,下一层是第二个,在下层第二个。这样就连接到最底层
图上每一个圈都有两条线
选 时就是上面一条,选 就是下面一条
题目来源
鸣谢南航 勇敢的加菲猫
数据规模与约定
的数据满足:,,。