제출 #522218

#제출 시각아이디문제언어결과실행 시간메모리
522218Aldas25다리 (APIO19_bridges)C++14
0 / 100
46 ms8948 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; 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 () { FOR(i, 1, n) { par[i] = i; sz[i] = 1; } 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"; } 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]; } solve4(); 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...