CF501C.Misha and Forest
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Let's define a forest as a non-directed acyclic graph (also without loops and parallel edges). One day Misha played with the forest consisting of n vertices. For each vertex v from 0 to n - 1 he wrote down two integers, degree__v and s__v, were the first integer is the number of vertices adjacent to vertex v, and the second integer is the XOR sum of the numbers of vertices adjacent to v (if there were no adjacent vertices, he wrote down 0).
Next day Misha couldn't remember what graph he initially had. Misha has values degree__v and s__v left, though. Help him find the number of edges and the edges of the initial graph. It is guaranteed that there exists a forest that corresponds to the numbers written by Misha.
我们定义森林为一个无向的无环图(且不含自环和平行边)。某天,米沙玩了一个包含 n 个顶点的森林。对于从 0 到 n−1 的每个顶点 v,他记录了两个整数:degreev 和 sv,其中第一个整数表示与顶点 v 相邻的顶点个数,第二个整数表示与顶点 v 相邻的所有顶点编号的异或和(若没有相邻顶点,则记为 0)。
第二天,米沙已记不清他最初画的是哪个图了,但他仍保留着所有 degreev 和 sv 的值。请你帮助他还原出初始图的边数及所有具体的边。题目保证存在一个森林与米沙所记录的数值完全对应。
输入格式
The first line contains integer n (1 ≤ n ≤ 216), the number of vertices in the graph.
The i-th of the next lines contains numbers degree__i and s__i (0 ≤ degree__i ≤ n - 1, 0 ≤ s__i < 216), separated by a space.
第一行包含一个整数 n(1≤n≤216),表示图中顶点的数量。
接下来的第 i 行包含两个数 degreei 和 si(0≤degreei≤n−1,0≤si<216),以空格分隔。
输出格式
In the first line print number m, the number of edges of the graph.
Next print m lines, each containing two distinct numbers, a and b (0 ≤ a ≤ n - 1, 0 ≤ b ≤ n - 1), corresponding to edge (a, b).
Edges can be printed in any order; vertices of the edge can also be printed in any order.
第一行输出整数 m,表示图中边的数量。
接下来输出 m 行,每行包含两个不同的整数 a 和 b(满足 0 ≤ a ≤ n − 1,0 ≤ b ≤ n − 1),对应一条边 (a, b)。
边的输出顺序可以任意;每条边的两个顶点的输出顺序也可以任意。
输入输出样例
输入#1
3 2 3 1 0 1 0
输出#1
2 1 0 2 0
输入#2
2 1 1 1 0
输出#2
1 0 1
说明/提示
The XOR sum of numbers is the result of bitwise adding numbers modulo 2. This operation exists in many modern programming languages. For example, in languages C++, Java and Python it is represented as "^", and in Pascal — as "xor".
数字的异或和(XOR sum)是将数字按位相加后对 2 取模的结果。该运算存在于许多现代编程语言中。例如,在 C++、Java 和 Python 中用符号 “^” 表示,在 Pascal 中则用 “xor” 表示。
输入解题思路,AI测评打分。不知道怎么写?