A10107 | Lazy Student
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
输入格式
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}<=10^{9},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.
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}<=10^{9},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.
输出格式
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.
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
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
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted