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_水色精進記録16_ABC328f

Posted at

Atcoder水色精進記録

ABC328
F - Good Set Query
https://atcoder.jp/contests/abc328/tasks/abc328_f

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

重みつきUnionFind

考察

Xa - Xb = d → Xa = d + Xb
単一の式だけで考えれば、Xaが決まればXbが決まる
関連するa,bに辺が貼られたグラフとして考えれば閉路がなければ条件は成立している
閉路ができる場合、それまでの値と整合性を保てた状態で、繋ぐことができれば条件は成立

UnionFindで閉路検出はできる
UnionFindに重みを追加して、自分のルートとのdiffを保持しておけばOK

提出

感想

重みの更新が手癖で書けないので、書けるまで慣れたい
union時にfindせずにrootを使ってしまう癖があるので直す必要があり

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?