CF605B.Lazy Student

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Student Vladislav came to his programming exam completely unprepared as usual. He got a question about some strange algorithm on a graph — something that will definitely never be useful in real life. He asked a girl sitting next to him to lend him some cheat papers for this questions and found there the following definition:

The minimum spanning tree T of graph G is such a tree that it contains all the vertices of the original graph G, and the sum of the weights of its edges is the minimum possible among all such trees.

Vladislav drew a graph with n vertices and m edges containing no loops and multiple edges. He found one of its minimum spanning trees and then wrote for each edge its weight and whether it is included in the found tree or not. Unfortunately, the piece of paper where the graph was painted is gone and the teacher is getting very angry and demands to see the original graph. Help Vladislav come up with a graph so that the information about the minimum spanning tree remains correct.

学生弗拉迪斯拉夫像往常一样完全没做准备就来参加编程考试。他拿到一道关于图上某种奇怪算法的题目——这类东西在现实生活中肯定毫无用处。他向坐在旁边的女生借了几页作弊纸,上面找到了如下定义:

图 $ G $ 的最小生成树 $ T $ 是满足以下条件的一棵树:它包含原图 $ G $ 的所有顶点,且其所有边的权值之和在所有满足该条件的树中是最小的。

弗拉迪斯拉夫画了一个含有 $ n $ 个顶点和 $ m $ 条边的图,该图不含自环和平行边。他找出了该图的一棵最小生成树,然后对每条边记录了它的权值以及它是否被包含在这棵找到的生成树中。不幸的是,画有原图的那张纸丢失了,而老师正变得非常生气,并要求立刻看到原始图。请帮助弗拉迪斯拉夫构造出一个图,使得关于最小生成树的上述信息仍然成立。

输入格式

The first line of the input contains two integers n and m () — the number of vertices and the number of edges in the graph.

Each of the next m lines describes an edge of the graph and consists of two integers a__j and b__j (1 ≤ a__j ≤ 109, b__j = {0, 1}). The first of these numbers is the weight of the edge and the second number is equal to 1 if this edge was included in the minimum spanning tree found by Vladislav, or 0 if it was not.

It is guaranteed that exactly n - 1 number {b__j} are equal to one and exactly m - n + 1 of them are equal to zero.

输入的第一行包含两个整数 nn 和 mm()—— 分别表示图中顶点的数量和边的数量。

接下来的 mm 行每行描述图中的一条边,由两个整数 aja_j 和 bjb_j(1 ≤ aj ≤ 1091 \le a_j \le 10^9,bj ∈ {0, 1}b_j \in \{0, 1\})组成。其中第一个数表示该边的权重;第二个数若为 11,表示该边被弗拉迪斯拉夫所求得的最小生成树所包含,若为 00,则表示未被包含。

保证在所有 bjb_j 中,恰好有 n−1n-1 个等于 11,且恰好有 m−n+1m-n+1 个等于 00。

输出格式

If Vladislav has made a mistake and such graph doesn't exist, print  - 1.

Otherwise print m lines. On the j-th line print a pair of vertices (u__j, v__j) (1 ≤ u__j, v__j ≤ n, u__j ≠ v__j), that should be connected by the j-th edge. The edges are numbered in the same order as in the input. The graph, determined by these edges, must be connected, contain no loops or multiple edges and its edges with b__j = 1 must define the minimum spanning tree. In case there are multiple possible solutions, print any of them.

如果弗拉迪斯拉夫犯了错误,使得这样的图不存在,则输出 -1。

否则输出 m 行。在第 j 行输出一对顶点 (u_j, v_j)(其中 1 ≤ u_j, v_j ≤ n,且 u_j ≠ v_j),表示第 j 条边应连接这两个顶点。边的编号顺序需与输入中一致。由这些边所确定的图必须是连通的,且不含自环或重边;此外,满足 b_j = 1 的边必须构成该图的一棵最小生成树。若存在多种可能的解,输出任意一种即可。

输入输出样例

  • 输入#1

    4 5
    2 1
    3 1
    4 0
    1 1
    5 0

    输出#1

    2 4
    1 4
    3 4
    3 1
    3 2
  • 输入#2

    3 3
    1 0
    2 1
    3 1

    输出#2

    -1

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

首页