CF605B.Lazy Student

普及/提高-

通过率:0%

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 TT of graph GG is such a tree that it contains all the vertices of the original graph GG , and the sum of the weights of its edges is the minimum possible among all such trees.

Vladislav drew a graph with nn vertices and mm 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.

输入格式

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

Each of the next mm lines describes an edge of the graph and consists of two integers aja_{j} and bjb_{j} ( 1<=aj<=109,bj=0,11<=a_{j}<=10^{9},b_{j}={0,1} ). The first of these numbers is the weight of the edge and the second number is equal to 11 if this edge was included in the minimum spanning tree found by Vladislav, or 00 if it was not.

It is guaranteed that exactly n1n-1 number bj{b_{j}} are equal to one and exactly mn+1m-n+1 of them are equal to zero.

输出格式

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

Otherwise print mm lines. On the jj -th line print a pair of vertices (uj,vj)(u_{j},v_{j}) ( 1<=uj,vj<=n,ujvj1<=u_{j},v_{j}<=n,u_{j}≠v_{j} ), that should be connected by the jj -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 bj=1b_{j}=1 must define the minimum spanning tree. In case there are multiple possible solutions, print any of them.

输入输出样例

  • 输入#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
    
首页