제출 #1044791

#제출 시각아이디문제언어결과실행 시간메모리
1044791vjudge1다리 (APIO19_bridges)C++17
13 / 100
3090 ms3576 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...