結果
| 問題 |
No.2912 0次パーシステントホモロジー
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-10-04 22:03:07 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 205 ms / 2,000 ms |
| コード長 | 1,425 bytes |
| コンパイル時間 | 2,391 ms |
| コンパイル使用メモリ | 211,108 KB |
| 最終ジャッジ日時 | 2025-02-24 15:18:09 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
class UnionFind{
public:
vector<int> par,siz;
void make(int N){
par.resize(N,-1);
siz.resize(N,1);
}
int root(int x){
if(par.at(x) == -1) return x;
else return par.at(x) = root(par.at(x));
}
void unite(int u, int v){
u = root(u),v = root(v);
if(u == v) return;
if(siz.at(u) < siz.at(v)) swap(u,v);
par.at(v) = u;
siz.at(u) += siz.at(v);
}
bool issame(int u, int v){
if(root(u) == root(v)) return true;
else return false;
}
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int N,M; cin >> N >> M;
vector<vector<pair<int,int>>> Rs(100001);
for(int i=0; i<M; i++){
int u,v,w; cin >> u >> v >> w;
Rs.at(w).push_back({u,v});
}
int T; cin >> T;
vector<pair<int,int>> Ts(T);
for(int i=0; i<T; i++) cin >> Ts.at(i).first,Ts.at(i).second = i;
sort(Ts.begin(),Ts.end());
vector<int> answer(T);
int ans = N,nowr = 0;
UnionFind Z; Z.make(N);
for(auto [r,pos] : Ts){
while(nowr <= r){
for(auto [u,v] : Rs.at(nowr)){
if(Z.issame(u,v)) continue;
ans--;
Z.unite(u,v);
}
nowr++;
}
answer.at(pos) = ans;
}
for(auto a : answer) cout << a << endl;
}