Submission #979450

#TimeUsernameProblemLanguageResultExecution timeMemory
979450nninBridges (APIO19_bridges)C++17
13 / 100
3024 ms4680 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 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({t, {x, y}}); if(t==1) { edges[x-1].f = y; } else { init(); for(auto [w, u]:edges) { if(w>=y) join(u.f, u.s); } cout<<sz[par(x)]<<'\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...