제출 #522220

#제출 시각아이디문제언어결과실행 시간메모리
522220Aldas25다리 (APIO19_bridges)C++14
13 / 100
45 ms3524 KiB
#include <bits/stdc++.h> using namespace std; #define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr) #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define REP(n) FOR(O, 1, (n)) #define f first #define s second #define pb push_back typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<pii> vii; typedef vector<ll> vl; const int MAXN = 50100; int par[MAXN], sz[MAXN]; int find (int a) {return par[a] = par[a]==a ? a : find(par[a]);} bool same (int a, int b) {return find(a) == find(b);} void unite (int a, int b) { a = find(a); b = find(b); if (a==b) return; par[b] = a; sz[a] += sz[b]; } int n, m, q; void dsuReset () { FOR(i, 0, n) { par[i] = i; sz[i] = 1; } } int ui[MAXN], vei[MAXN], di[MAXN]; int ti[MAXN], ai[MAXN], bi[MAXN]; vector<pair<int, pii>> edges; int ans[MAXN]; vector<pair<pii, int>> queries; void solve4 () { dsuReset(); FOR(i, 1, m) { edges.pb({di[i], {ui[i], vei[i]}}); } sort(edges.begin(), edges.end()); reverse(edges.begin(), edges.end()); FOR(i, 1, q) { if (ti[i] == 2) { queries.pb({{bi[i], ai[i]}, i}); } } sort(queries.begin(), queries.end()); reverse(queries.begin(), queries.end()); int qId = 0, eId = 0; while (qId < (int)queries.size()) { if (eId < m && edges[eId].f >= queries[qId].f.f) { int u = edges[eId].s.f; int v = edges[eId].s.s; unite(u,v); eId++; } else { int v = queries[qId].f.s; int id = queries[qId].s; ans[id] = sz[find(v)]; qId++; } } FOR(i, 1, q) if (ti[i] == 2) cout << ans[i] << "\n"; } void solve1 () { FOR(i, 1, q) { if (ti[i] == 1) { int id = ai[i]; int newW = bi[i]; di[id] = newW; } else { dsuReset(); int v = ai[i]; int w = bi[i]; FOR(j, 1, m) { if (di[j] >= w) unite (ui[j], vei[j]); } cout << sz[find(v)] << "\n"; } } } int main() { FAST_IO; cin >> n >> m; FOR(i, 1, m) cin >> ui[i] >> vei[i] >> di[i]; cin >> q; FOR(i, 1, q) { cin >> ti[i] >> ai[i] >> bi[i]; } bool sub4 = true; FOR(i, 1, q) if (ti[i] != 2) sub4 = false; if (sub4) solve4(); else solve1(); return 0; }
#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...