結果
| 問題 | No.3639 Itsukin |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-08-26 10:56:27 |
| 言語 | C++23(gcc16) (gcc 16.1.0 + boost 1.90.0) |
| 結果 |
AC
|
| 実行時間 | 278 ms / 2,000 ms |
| + 69µs | |
| コード長 | 2,619 bytes |
| 記録 | |
| コンパイル時間 | 4,559 ms |
| コンパイル使用メモリ | 368,112 KB |
| 実行使用メモリ | 19,964 KB |
| 最終ジャッジ日時 | 2026-08-26 10:56:43 |
| 合計ジャッジ時間 | 13,258 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge3_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 点 |
ソースコード
// #define YUKICODER
#define CODEFORCES
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pob pop_back
#define eb emplace_back
#define nall(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define accu accumulate
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#ifdef CODEFORCES
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define yesno(a) cout<<(a?"YES\n":"NO\n")
#define yesnoout(a, b) cout<<(a?"YES\n":"NO")<<(a?b:"")<<"\n"
#else
#define yes cout<<"Yes\n"
#define no cout<<"No\n"
#define yesno(a) cout<<(a?"Yes\n":"No\n")
#define yesnoout(a, b) cout<<(a?"Yes\n":"No")<<(a?b:"")<<"\n"
#endif
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<class T> using pq = priority_queue<T>;
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
template<class T> using vec = vector<T>;
template<class T> using vv = vector<vector<T>>;
template<class T> using vvv = vector<vv<T>>;
const ll MOD = 998244353ll;
// const ll MOD = 1000000007ll;
// template
struct dsu{
vector<int> par, sz;
dsu(int n){
par.resize(n);
sz.assign(n, 1);
iota(par.begin(), par.end(), 0);
}
int root(int x){
if (par[x] == x) return x;
return par[x] = root(par[x]);
}
bool merge(int x, int y){
x = root(x), y = root(y);
if (x == y) return false;
if (sz[x] < sz[y]) swap(x, y);
par[y] = x, sz[x] += sz[y];
return true;
}
bool same(int x, int y){
return root(x) == root(y);
}
int size(int x){
return sz[root(x)];
}
};
void solve();
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
unsigned T = 1;
// cin >> T;
cout << fixed << setprecision(20);
while (T--) solve();
return 0;
}
void solve(){
int N, M, Q;
cin >> N >> M;
vec<tuple<int, int, int, int>> T;
rep(i, M){
int u, v, l;
cin >> u >> v >> l;
u--, v--;
T.emplace_back(1, l, u, v);
}
cin >> Q;
rep(i, Q){
int p, t;
cin >> p >> t;
t--;
T.emplace_back(2, p, t, i);
}
sort(nall(T), [](auto x, auto y){
if (get<1>(x) == get<1>(y)) return get<0>(x) < get<0>(y);
return get<1>(x) < get<1>(y);
});
dsu uf(N);
vec<int> ans(Q);
for (auto [t, p, u, v] : T){
if (t == 1) uf.merge(u, v);
else ans[v] = uf.size(u);
}
for (int x : ans) cout << x << endl;
}