제출 #1119024

#제출 시각아이디문제언어결과실행 시간메모리
1119024PagodePaiva다리 (APIO19_bridges)C++17
0 / 100
748 ms524288 KiB
#include<bits/stdc++.h> using namespace std; const int N = 50010; vector <array <int, 3>> mst; vector <array <int, 3>> arestas; int ordem_arestas[N]; struct DSU{ int pai[N], sz[N]; DSU(){ for(int i = 1;i < N;i++){ pai[i] = i; sz[i] = 1; } } int find(int x){ return pai[x] = (pai[x] == x ? x : find(pai[x])); } void join(int a, int b, int w){ a = find(a); b = find(b); if(a == b) return; mst.push_back({w, a, b}); if(sz[a] > sz[b]) swap(a, b); pai[a] = b; sz[b] += sz[a]; return; } } dsu; vector <array<int, 3>> queries; int res[N]; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n, m, q; cin >> n >> m; for(int i = 0;i < m;i++){ int a, b, w; cin >> a >> b >> w; arestas.push_back({w, a, b}); } sort(arestas.begin(), arestas.end()); cin >> q; for(int i = 0;i < q;i++){ int t, a, b; cin >> t >> a >> b; queries.push_back({b, a, i}); } sort(queries.begin(), queries.end()); while(queries.size() > 0){ auto [ww, s, i] = queries.back(); while(arestas.size() > 0){ auto [w, a, b] = arestas.back(); if(w < ww) break; dsu.join(a, b, w); arestas.pop_back(); } res[i] = dsu.sz[dsu.find(s)]; queries.pop_back(); } for(int i = 0;i < q;i++){ cout << res[i] << '\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...