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

19220번 - Cactus Revenge 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 512 MB35141341.935%

문제

NE(E)RC featured a number of problems in previous years about cactuses --- connected undirected graphs in which every edge belongs to at most one simple cycle. Intuitively, a cactus is a generalization of a tree where some cycles are allowed. The traditional cactus that was initially used in NEERC 2005 problem is given on the second picture in the Examples section.

You are given $n$ integers $d_1, d_2, \ldots, d_n$. Construct any cactus with $n$ vertices such that vertex $i$ has degree $d_i$ (i. e. exactly $d_i$ incident edges), or determine that no such cactus exists. Parallel edges and loops are not allowed.

입력

The first line contains a single integer $n$ (2ドル \le n \le 2,000円$) --- the number of vertices in the cactus.

The second line contains $n$ integers $d_1, d_2, \ldots, d_n$ (1ドル \le d_i \le n-1$) --- the desired vertex degrees.

출력

If it's impossible to construct a cactus satisfying the conditions, output a single integer $-1$.

Otherwise, by tradition, output the constructed cactus as a set of edge-distinct paths.

In the first line output an integer $m$ --- the number of such paths. Each of the following $m$ lines should contain a path in the graph. A path should start with an integer $k_i$ ($k_i \ge 2$) followed by $k_i$ integers from 1ドル$ to $n$. These $k_i$ integers should represent consecutive vertices of this path. Adjacent vertices in the path should be distinct. The path can visit the same vertex multiple times, but every edge of the cactus should be traversed exactly once in the whole output.

제한

예제 입력 1

5
2 2 3 2 1

예제 출력 1

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

예제 입력 2

4
3 3 2 2

예제 출력 2

-1

예제 입력 3

6
1 2 1 1 2 1

예제 출력 3

-1

예제 입력 4

15
1 4 3 2 2 2 2 2 4 4 2 2 2 2 2

예제 출력 4

3
9 1 2 3 4 5 6 7 8 3
7 2 9 10 11 12 13 10
5 2 14 9 15 10

노트

Both in the second and the third example, there exist graphs that satisfy the given conditions but none of them are cactuses.

출처

ICPC > Regionals > Northern Eurasia > Northern Eurasia Finals > Northern Eurasia Finals 2019 C번

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

출처

대학교 대회

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

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