Graph Director

시간 제한1초메모리 제한2048 MB

요약
각 무향 간선의 방향을 정해서 정점 j에서 도달 가능한 정점 수가 정확히 A_j가 되도록 만들고, 불가능하면 -1을 출력한다.
난이도

어려움10점 중 8점

유형
그래프, DFS, 그리디, 구현
정답자
아직 제출이 없습니다

문제

You are given a simple graph consisting of NN vertices (numbered from 11 to NN) and MM bidirectional edges (numbered from 11 to MM). Edge ii connects vertices U_iU\_i and V_iV\_i. You are asked to convert each edge into a directed edge. For each edge ii, you can choose to direct it from U_iU\_i to V_iV\_i or in the opposite direction.

The final directed graph has to satisfy the following requirements. For each vertex jj, there are exactly A_jA\_j different possible vertices that can be visited by a walk starting from vertex jj. 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 NN MM (2≤N≤20002 ≤ N ≤ 2000; 1≤M≤40001 ≤ M ≤ 4000).

Each of the next MM lines consists of two integers U_iU\_i V_iV\_i (1≤U_i,V_i≤N1 ≤ U\_i , V\_i ≤ N). There are no self-loops or multiedges.

The following line consists of NN integers A_jA\_j (1≤A_j≤N1 ≤ A\_j ≤ N).

출력

If it is impossible to direct the edges in a way that meets the requirements, output -1.

Otherwise, output MM lines, each containing two integers uu and vv representing a directed edge from vertex uu to vv in your final directed graph. You can output the edges in any order. If there are several solutions, you can output any of them.

예제3

  1. 예제 1

    입력
    6 7
    3 1
    1 4
    1 5
    3 2
    2 1
    3 4
    5 6
    6 1 6 6 2 1
    
    예상 출력
    1 5
    3 2
    1 2
    5 6
    1 3
    3 4
    4 1
    
  2. 예제 2

    입력
    3 2
    1 2
    2 3
    2 1 3
    
    예상 출력
    -1
    
  3. 예제 3

    입력
    3 1
    1 2
    2 1 1
    
    예상 출력
    1 2