Graph Director
시간 제한1초메모리 제한2048 MB
각 무향 간선의 방향을 정해서 정점 j에서 도달 가능한 정점 수가 정확히 A_j가 되도록 만들고, 불가능하면 -1을 출력한다.
문제
You are given a simple graph consisting of vertices (numbered from to ) and bidirectional edges (numbered from to ). Edge connects vertices and . You are asked to convert each edge into a directed edge. For each edge , you can choose to direct it from to or in the opposite direction.

The final directed graph has to satisfy the following requirements. For each vertex , there are exactly different possible vertices that can be visited by a walk starting from vertex . A walk consists of traversing zero or more directed edges, following the direction in the final directed graph.
Direct the edges, or determine whether it is impossible to achieve. If there are several solutions, you can choose any of them.
입력
The first line consists of two integers (; ).
Each of the next lines consists of two integers (). There are no self-loops or multiedges.
The following line consists of integers ().
출력
If it is impossible to direct the edges in a way that meets the requirements, output -1.
Otherwise, output lines, each containing two integers and representing a directed edge from vertex to in your final directed graph. You can output the edges in any order. If there are several solutions, you can output any of them.