問題一覧 > 通常問題

No.1480 Many Complete Graphs

レベル : / AI推定難易度 : 1950 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 61
作問者 : PCTprobability / テスター : fairy_lettuce 蜜蜂 nok0 ygussany
お気に入りにしたユーザー ProblemId : 5945 / 自分の提出
問題文最終更新日: 2021-04-16 23:06:03
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 291 (順位表) の他の問題:

About the evil case

It was discovered that an unintended pruning solution passes this problem, so we have decided to add, as an evil case, a case in which the constraint is multiplied by $2$.

We apologize for this.

Problem Statement

There is an undirected graph with $N$ vertices numbered from $1$ to $N$ and $0$ edges. Perform the following operation on this graph $M$ times.

In the $i$-th operation, positive integers $k_i,c_i$ and a sequence $s_1,s_2,\dots,s_{k_i}$ of length $k_i$ are given. For every pair of integers $(x,y)$ satisfying $1\le x < y \le k_i$, add an undirected edge of length $\displaystyle \left\lceil{\frac{s_x+s_y}{2}}\right\rceil + c_i$ connecting vertex $s_x$ and vertex $s_y$. Here, $\displaystyle \lceil x \rceil$ denotes the smallest integer greater than or equal to the real number $x$.

Find the minimum length of a path from vertex $1$ to vertex $N$ in the graph after all $M$ operations have been performed.

If there is no path from vertex $1$ to vertex $N$, output $-1$ instead.

Input

$N\ M$
$k_1\ c_1\ s_{1,1}\ s_{1,2}\ ...\ s_{1,k_1}$
$k_2\ c_2\ s_{2,1}\ s_{2,2}\ ...\ s_{2,k_2}$
$\vdots$
$k_M\ c_M\ s_{M,1}\ s_{M,2}\ ...\ s_{M,k_M}$

  • All inputs are integers.
  • $1 \le N \le 10^5$
  • $0 \le M \le 10^5$
  • $2 \le k_i \le N$
  • $1 \le c_i \le 10^9$
  • $1 \le s_{i,1} < s_{i,2} < ... < s_{i,k_i} \le N$
  • $ \displaystyle \sum_{i=1}^{M}k_i \le 10^5$
  • The following are the constraints of the evil case. This case does not affect the judgment of correctness. Only the last constraint differs.

  • All inputs are integers.
  • $1 \le N \le 10^5$
  • $0 \le M \le 10^5$
  • $2 \le k_i \le N$
  • $1 \le c_i \le 10^9$
  • $1 \le s_{i,1} < s_{i,2} < ... < s_{i,k_i} \le N$
  • $ \displaystyle \sum_{i=1}^{M}k_i \le 2 \times 10^5$
  • Output

    Find the minimum length of a path from vertex $1$ to vertex $N$ in the graph after all $M$ operations have been performed.

    If there is no path from vertex $1$ to vertex $N$, output $-1$ instead.

    Sample

    Sample 1
    Input
    3 1
    3 1 1 2 3
    Output
    3

    In the $1$-st operation, an edge of length $3$ is added between vertices $1,2$, an edge of length $3$ is added between vertices $1,3$, and an edge of length $4$ is added between vertices $2,3$. After all operations have finished, the length of the shortest path from vertex $1$ to vertex $3$ is $3$.

    Sample 2
    Input
    8 2
    4 1000000000 1 2 3 4
    4 1000000000 5 6 7 8
    Output
    -1

    There may be no path from vertex $1$ to vertex $N$.

    Sample 3
    Input
    18 8
    6 11 1 3 5 6 9 13
    10 20 2 3 4 6 7 10 13 14 16 17
    9 10 1 4 5 10 11 13 14 16 17
    10 6 4 5 7 10 11 13 14 15 16 18
    2 9 5 12
    9 4 2 4 6 8 9 10 14 15 16
    7 18 1 2 4 8 10 11 18
    4 17 2 3 8 10
    Output
    28

    提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。