Created
March 12, 2026 11:03
-
-
Save maehrm/eb29c2b3f85695d46b24e5063adb1d6e to your computer and use it in GitHub Desktop.
E - Graph Destruction https://atcoder.jp/contests/abc229/tasks/abc229_e
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from atcoder.dsu import DSU | |
| N, M = map(int, input().split()) | |
| G = [[] * N for _ in range(N)] | |
| for _ in range(M): | |
| a, b = map(lambda x: int(x) - 1, input().split()) | |
| G[a].append(b) | |
| dsu = DSU(N) | |
| curr = 0 | |
| ans = [] | |
| for u in range(N - 1, -1, -1): | |
| ans.append(str(curr)) | |
| curr += 1 | |
| for v in G[u]: | |
| if dsu.same(u, v): | |
| continue | |
| dsu.merge(u, v) | |
| curr -= 1 | |
| print("\n".join(ans[::-1])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment