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

20354번 - Blackboard Reconstruction 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB28131348.148%

문제

Harry is a mathematician who likes to play with graphs. He has drawn a weighted undirected graph on the blackboard, and computed that the length of the shortest path between two nodes is s. Unfortunately he has to leave the room, therefore he quickly writes down s and the weights of all edges on a piece of paper, and he wipes the blackboard. Then it dawns on him: this information is not enough to reconstruct his beautiful graph!

Write a program that constructs some graph matching the information that Harry wrote down.

입력

The input consists of:

  • one line with two integers s and e (1 ≤ s ≤ 104, 1 ≤ e ≤ 1 000), the length of the shortest path and the number of edges;
  • e lines, each with an integer w (0 ≤ w ≤ 104), the length of an edge.

출력

Output a graph consisting of a number of 1-indexed nodes and exactly e edges, such that the edge lengths correspond to the lengths in the input, and the length of the shortest path between nodes 1 and 2 is s. The graph must be connected, must not contain self-loops and can have at most one edge between each pair of nodes. You may assume that such a graph exists.

The output must consist of:

  • one line with an integer n (2 ≤ n ≤ e + 1), the number of nodes;
  • e lines, each with three integers a, b and w (1 ≤ a, b ≤ n), describing an edge between nodes a and b with length w.

If there are multiple correct answers, you may give any of them.

제한

예제 입력 1

4 5
1
5
3
2
2

예제 출력 1

4
1 3 1
1 4 2
4 2 2
3 2 3
3 4 5

힌트

출처

ICPC > Regionals > Europe > Northwestern European Regional Contest > NWERC 2016 연습 세션 PB번

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

출처

대학교 대회

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

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