This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define fast cin.tie(0)->sync_with_stdio(0);
#define int long long
#define inf ((int)1e18)
using namespace std;
vector <int> par, w;
int parent(int node) {
if(par[node] == node) return node;
return par[node] = parent(par[node]);
}
void dsu(int a, int b) {
a = parent(a);
b = parent(b);
if(a == b) return;
if(w[a] < w[b]) swap(a, b);
// a ya byi ekle
w[a] += w[b];
par[b] = par[a];
}
int32_t main(){
fast
int n, m;
cin >> n >> m;
vector <array<int, 3> > edges;
for(int i = 0; i < m; i++) {
int a, b, c;
cin >> a >> b >> c;
edges.push_back({a, b, c});
}
int q;
cin >> q;
while(q--) {
int type, a, b;
cin >> type >> a >> b;
if(type == 1) {
edges[a - 1][2] = b;
}
else {
par.assign(n + 1, 0);
w.assign(n + 1, 0);
for(int i = 1; i <= n; i++) {
par[i] = i;
w[i] = 1;
}
for(auto [from, to, we]:edges) {
// cout << from << " " << to << " " << we << "\n";
if(we >= b) {
// cout << from << " " << to << "\n";
dsu(from, to);
}
}
cout << w[parent(a)] << "\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... |