結果
問題 |
No.2912 0次パーシステントホモロジー
|
ユーザー |
![]() |
提出日時 | 2024-10-07 01:55:23 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 162 ms / 2,000 ms |
コード長 | 758 bytes |
コンパイル時間 | 2,294 ms |
コンパイル使用メモリ | 208,556 KB |
最終ジャッジ日時 | 2025-02-24 16:15:09 |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
#include <bits/stdc++.h> using namespace std; void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); } #include <atcoder/dsu> using namespace atcoder; int main() { fast_io(); int n, m; cin >> n >> m; vector<tuple<int, int, int>> edges; for (int i = 0; i < m; i++) { int u, v, w; cin >> u >> v >> w; edges.push_back({w, u, v}); } sort(edges.begin(), edges.end()); dsu uf(n); int cur = 0; int components = n; vector<int> ans(1e5 + 1, n); for (auto [w, u, v] : edges) { if (uf.same(u, v)) continue; components--; ans[w] = components; uf.merge(u, v); } for (int i = 1; i <= 1e5; i++) { if (ans[i] == n) ans[i] = ans[i - 1]; } int t; cin >> t; for (; t--;) { int r; cin >> r; cout << ans[r] << '\n'; } }