問題一覧 > 通常問題

No.3200 Sinking Islands

レベル : / AI推定難易度 : 1100 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 119
作問者 : YY-otter / テスター : nauclhlt
お気に入りにしたユーザー ProblemId : 12433 / 自分の提出
問題文最終更新日: 2025-07-11 11:51:02
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 473 第1回 生成AI作問コンテスト (順位表) の他の問題:

Problem Statement

There are $N$ islands and $M$ bridges connecting them. Bridge $i\ (1\leq i\leq M)$ connects islands $U_i,V_i$.
Initially, some of the islands are connected to each other by these $M$ bridges.

However, due to large-scale crustal movements, these bridges collapse at a rate of $1$ bridge every $1$ day.
You are given a collapse schedule spanning $Q$ days. On day $i$ $(1\leq i\leq Q)$, bridge $B_i$ collapses and becomes impassable.

As the country's Minister of Transport, you must report at the end of each day the total number of pairs of islands that cannot reach each other.
For each day $i=1,2,\dots,Q$, compute the total number of pairs of islands that cannot reach each other after that day's bridge collapse.

Formally, for each day $i$ $(1\leq i\leq Q)$, find the following value after that day's bridge collapse.

  • The number of pairs of integers $(i,j)$ satisfying $1\leq i<j\leq N$ such that islands $i$ and $j$ cannot reach each other no matter how many bridges are used

Input

$N\ M$
$U_1\ V_1$
$\dots$
$U_M\ V_M$
$Q$
$B_1$
$\dots$
$B_Q$

  • $2\leq N\leq 2\times 10^5$
  • $1\leq M\leq 2\times 10^5$
  • $1\leq U_i,V_i\leq N\ (1\leq i\leq M)$
  • $U_i\neq V_i\ (1\leq i\leq M)$
  • $1\leq Q\leq M$
  • $1\leq B_i\leq M\ (1\leq i\leq Q)$
  • $B_i\neq B_j\ (1\leq i,j\leq Q,i\neq j)$

Output

Output $Q$ lines, separated by newlines, giving the total number of pairs of islands that cannot reach each other at the end of each day.
Print a newline at the end.

Sample

Sample 1
Input
4 5
1 2
2 3
3 4
1 3
1 4
3
5
2
4
Output
0
0
4
  • Initial state: All islands are connected by the 5 bridges.
  • Day 1: Bridge $5$ (1-4) collapses. All islands are still connected. Number of disconnected pairs = $0$.
  • Day 2: Bridge $2$ (2-3) collapses. Islands {1,2,3,4} are still connected. Number of disconnected pairs = $0$.
  • Day 3: Bridge $4$ (1-3) collapses. The islands split into $2$ groups: islands {1,2} and islands {3,4}.
    The disconnected pairs are the $4$ pairs (1,3),(1,4),(2,3),(2,4).
Sample 2
Input
3 2
1 2
1 2
2
2
1
Output
2
3

There may be pairs of islands that cannot reach each other from the start, and there may be multiple bridges connecting the same pair of islands.

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