#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';
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
34 ms |
600 KB |
Output is correct |
4 |
Correct |
17 ms |
604 KB |
Output is correct |
5 |
Correct |
17 ms |
600 KB |
Output is correct |
6 |
Correct |
13 ms |
604 KB |
Output is correct |
7 |
Correct |
18 ms |
344 KB |
Output is correct |
8 |
Correct |
16 ms |
604 KB |
Output is correct |
9 |
Correct |
12 ms |
348 KB |
Output is correct |
10 |
Correct |
14 ms |
600 KB |
Output is correct |
11 |
Correct |
14 ms |
604 KB |
Output is correct |
12 |
Correct |
15 ms |
608 KB |
Output is correct |
13 |
Correct |
16 ms |
604 KB |
Output is correct |
14 |
Correct |
23 ms |
860 KB |
Output is correct |
15 |
Correct |
24 ms |
600 KB |
Output is correct |
16 |
Correct |
12 ms |
348 KB |
Output is correct |
17 |
Correct |
14 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3024 ms |
2920 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3033 ms |
2488 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
56 ms |
4348 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3024 ms |
2920 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
34 ms |
600 KB |
Output is correct |
4 |
Correct |
17 ms |
604 KB |
Output is correct |
5 |
Correct |
17 ms |
600 KB |
Output is correct |
6 |
Correct |
13 ms |
604 KB |
Output is correct |
7 |
Correct |
18 ms |
344 KB |
Output is correct |
8 |
Correct |
16 ms |
604 KB |
Output is correct |
9 |
Correct |
12 ms |
348 KB |
Output is correct |
10 |
Correct |
14 ms |
600 KB |
Output is correct |
11 |
Correct |
14 ms |
604 KB |
Output is correct |
12 |
Correct |
15 ms |
608 KB |
Output is correct |
13 |
Correct |
16 ms |
604 KB |
Output is correct |
14 |
Correct |
23 ms |
860 KB |
Output is correct |
15 |
Correct |
24 ms |
600 KB |
Output is correct |
16 |
Correct |
12 ms |
348 KB |
Output is correct |
17 |
Correct |
14 ms |
344 KB |
Output is correct |
18 |
Execution timed out |
3024 ms |
2920 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |