category-wise-problems

contains category wise problems(data structures, competitive) of popular platforms.

View the Project on GitHub mayankdutta/category-wise-problems

E - Graph Destruction

Approach

DSU snippets

Code ```cpp int n, m; cin >> n >> m; std ::vector<std ::vector> graph(n + 1); for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; graph[a].push_back(b); graph[b].push_back(a); } dsu.init(n + 10); std ::vector ans{0}; int count = 0; for (int u = n; u >= 2; u--) { count++; for (const auto &v : graph[u]) { if (v < u) continue; if (!dsu.isSameSet(u, v)) { dsu.unionSet(v, u); count--; } } ans.push_back(count); } reverse((ans).begin(), (ans).end()); for (const auto &i : ans) cout << i << '\n'; ``` </details>