Logo
(追記) (追記ここまで)

7473번 - Destroying The Graph 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 512 MB308750.000%

문제

Alice and Bob play the following game. First, Alice draws some directed graph with N vertices and M arcs. After that Bob tries to destroy it. In a move he may take any vertex of the graph and remove either all arcs incoming into this vertex, or all arcs outgoing from this vertex.

Alice assigns two costs to each vertex: Wi+ and Wi-. If Bob removes all arcs incoming into the i-th vertex he pays Wi+ dollars to Alice, and if he removes outgoing arcs he pays Wi- dollars. Find out what minimal sum Bob needs to remove all arcs from the graph.

입력

Input file describes the graph Alice has drawn. The first line of the input file contains N and M (1 ≤ N ≤ 100, 1 ≤ M ≤ 5000). The second line contains N integer numbers specifying Wi+ . The third line defines Wi- in a similar way. All costs are positive and do not exceed 106 . Each of the following M lines contains two integers describing the corresponding arc of the graph. Graph may contain loops and parallel arcs.

출력

On the first line of the output file print W - the minimal sum Bob must have to remove all arcs from the graph. On the second line print K - the number of moves Bob needs to do it. After that print K lines that describe Bob’s moves. Each line must first contain the number of the vertex and then + or - character, separated by one space. Character + means that Bob removes all arcs incoming into the specified vertex and - that Bob removes all arcs outgoing from the specified vertex.

제한

예제 입력 1

3 6
1 2 3
4 2 1
1 2
1 1
3 2
1 2
3 1
2 3

예제 출력 1

5
3
1 +
2 -
2 +

힌트

출처

ICPC > Regionals > Northern Eurasia > Northwestern Russia Regional Contest > NEERC Northern Subregional 2003 D번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /