結果
| 問題 | No.3639 Itsukin |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-08-28 01:06:00 |
| 言語 | C++17 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 144 ms / 2,000 ms |
| + 221µs | |
| コード長 | 1,665 bytes |
| 記録 | |
| コンパイル時間 | 1,501 ms |
| コンパイル使用メモリ | 225,556 KB |
| 実行使用メモリ | 12,800 KB |
| 最終ジャッジ日時 | 2026-08-28 01:06:13 |
| 合計ジャッジ時間 | 9,156 ms |
|
ジャッジサーバーID (参考情報) |
judge3_1 / judge2_0 |
(要ログイン)
| サブタスク | 配点 | 結果 |
|---|---|---|
| サンプル | 0 % | AC * 1 |
| 小課題1 | 10 % | AC * 6 |
| 小課題2 | 15 % | AC * 5 |
| 小課題3 | 15 % | AC * 16 |
| 小課題4 | 20 % | AC * 10 |
| 小課題5 | 10 % | AC * 15 |
| 小課題6 | 30 % | AC * 35 |
| 合計 | 100 点 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
class UnionFind{
private:
vector<int> par,siz;
public:
UnionFind(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));
}
bool unite(int u, int v){ //u,vを連結する 連結してた->false,した->trueを返す.
u = root(u),v = root(v);
if(u == v) return false;
if(siz.at(u) < siz.at(v)) swap(u,v); //Union by size.
par.at(v) = u;
siz.at(u) += siz.at(v);
return true;
}
bool issame(int u, int v){ //同じ連結成分ならtrue.
if(root(u) == root(v)) return true;
else return false;
}
int size(int pos){return siz.at(root(pos));} //posの連結成分の大きさを返す.
};
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int N,M; cin >> N >> M;
vector<tuple<int,int,int>> edge(M);
for(auto &[a,b,c] : edge) cin >> b >> c >> a,b--,c--;
sort(edge.begin(),edge.end());
int Q; cin >> Q;
vector<int> answer(Q);
vector<tuple<int,int,int>> Query(Q);
for(int i=0; i<Q; i++){
int p,t; cin >> p >> t,t--;
Query.at(i) = {p,t,i};
}
sort(Query.begin(),Query.end());
int epos = 0;
UnionFind Z(N);
for(auto [p,t,qpos] : Query){
while(epos < M){
auto [a,u,v] = edge.at(epos);
if(a <= p) Z.unite(u,v),epos++;
else break;
}
answer.at(qpos) = Z.size(t);
}
for(auto a : answer) cout << a << "\n";
}