0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

atcoder_水色精進記録15_ABC235e

Posted at

Atcoder水色精進記録

ABC235
E - MST + 1
https://atcoder.jp/contests/abc235/tasks/abc235_e

アルゴリズム・データ構造

クラスカル法,UnionFind,クエリ並列化

考察

最小全域木になる辺の選び方は、全ての辺をコストが昇順になるようにsortし、
辺の両端が同じrootでなければその辺を利用、既に同じrootであればその辺は利用せずに、次の辺を確認する。利用する辺がN-1まで上記を実施すればOK
計算量はO(MlogM)

各クエリで追加される辺がMSTに含まれるかどうかをMSTが完成している状態から判定するのは難しいので、最初にクエリで追加される辺を全て辺に加えておいて考える。
クエリで追加される辺がMSTに選ばれた場合は、次のクエリに影響を与えないように、MSTには加えずにスキップする処理を追加すれば一度のMSTの構築で全クエリの結果を計算することができる。

提出

感想

クエリを先読みして並列で考える方法が思い浮かんだのは成長を感じる。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?