제출 #979452

#제출 시각아이디문제언어결과실행 시간메모리
979452nnin다리 (APIO19_bridges)C++17
0 / 100
61 ms5232 KiB
#include<bits/stdc++.h> using namespace std; #define pii pair<int,int> #define pip pair<int,pii> #define f first #define s second int n, m, q; vector<pip> edges, query; int ans[100005]; int dsu[50005], sz[50005]; int par(int x) { if(dsu[x]==x) return x; return dsu[x] = par(dsu[x]); } void init() { for(int i=1;i<=n;i++) { dsu[i] = i; sz[i] = 1; } } void join(int a, int b) { int pa = par(a); int pb = par(b); if(pa!=pb) { dsu[pa] = pb; sz[pb] += sz[pa]; } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin>>n>>m; for(int i=0;i<m;i++) { int u, v, w; cin>>u>>v>>w; edges.push_back({w, {u, v}}); } cin>>q; for(int i=0;i<q;i++) { int t, x, y; cin>>t>>x>>y; query.push_back({y, {x, i}}); } sort(edges.begin(), edges.end()); sort(query.begin(), query.end()); int e = m-1; for(int i=q-1;i>=0;i--) { int w = query[i].f; int island = query[i].s.f; int idx = query[i].s.s; while(e>=0 && edges[e].f>=w) { join(edges[e].s.f, edges[e].s.s); e--; } ans[idx] = sz[par(island)]; } for(int i=0;i<q;i++) cout<<ans[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...