이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e4 + 25;
int n, m;
struct DSU {
int sze[MAXN], par[MAXN];
void init (int n) {
for (int i = 1; i <= n; i++) {
sze[i] = 1; par[i] = i;
}
}
int find (int x) {
return par[x] == x ? x : par[x] = find(par[x]);
}
void merge (int a, int b) {
a = find(a); b = find(b);
if (a == b) return;
if (sze[a] > sze[b]) swap(a, b);
sze[b] += sze[a]; par[a] = b;
}
} cur;
array <int, 3> p[MAXN];
int main () {
cin >> n >> m;
for (int i = 1; i <= m; i++) {
int a, b, c; cin >> a >> b >> c; p[i] = {a, b, c};
}
int q; cin >> q;
while (q--) {
int t; cin >> t;
if (t == 1) {
int a, b; cin >> a >> b; p[a][2] = b;
} else {
int x, y; cin >> x >> y;
cur.init(n);
for (int i = 1; i <= m; i++) {
if (p[i][2] >= y) {
cur.merge(p[i][0], p[i][1]);
}
}
cout << cur.sze[cur.find(x)] << '\n';
}
}
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |