제출 #129740

#제출 시각아이디문제언어결과실행 시간메모리
129740pr3pony다리 (APIO19_bridges)C++14
59 / 100
3026 ms12108 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N = 51212, M = 121212, Q = 121212; typedef pair<int,int> pii; typedef pair<ll,ll> pll; #define F first #define S second pii e[M]; int d[M], la[M], ans[Q], dsu[N], vis[N], vct; vector<int> g[N]; int find(int u) {return dsu[u] < 0 ? u : dsu[u] = find(dsu[u]);} void meld(int u,int v) { u = find(u), v = find(v); if (u == v) return; if (dsu[v] < dsu[u]) swap(u,v); dsu[u] += dsu[v]; dsu[v] = u; } set<pii,greater<pii>> se; int main() { ios::sync_with_stdio(0); cin.tie(0); int n,m,q; cin >> n >> m; for (int i = 1; i <= m; ++i) { cin >> e[i].F >> e[i].S >> d[i]; se.emplace(d[i],i); } const int BS = sqrt(n+m)+1; vector<tuple<int,int,int>> qry; // w, vertex id, time vector<tuple<int,int,int,int>> ce; // edge id, time l, time r, w cin >> q; for (int i = 1, lt = 0; i <= q; ++i) { int a,b,c; cin >> a >> b >> c; if (a == 1) { ce.emplace_back(b,la[b],i-1,d[b]); la[b] = i; se.erase({d[b],b}); d[b] = c; se.emplace(d[b],b); } else { qry.emplace_back(c,b,i); } if (i - lt == BS || i == q) { for (int j = 1; j <= m; ++j) if (la[j] > lt) ce.emplace_back(j,la[j],i,d[j]); auto it = begin(se); sort(begin(qry),end(qry),greater<decltype(qry[0])>()); fill_n(dsu,n+1,-1); for (const auto & tu : qry) { int w,vi,t; tie(w,vi,t) = tu; for (;it != end(se) && it->F >= w; ++it) { int ei = it->S; if (la[ei] <= lt) { meld(e[ei].F,e[ei].S); } } vector<int> cv; for (const auto & eu : ce) { int ei,tl,tr,ew; tie(ei,tl,tr,ew) = eu; int u = find(e[ei].F), v = find(e[ei].S); if (tl <= t && t <= tr && u != v && ew >= w) { g[u].emplace_back(v); g[v].emplace_back(u); cv.emplace_back(u); cv.emplace_back(v); } } vi = find(vi); int ta = dsu[vi]; queue<int> qu; qu.push(vi); vis[vi] = ++vct; while (qu.size()) { int u = qu.front(); qu.pop(); for (int v : g[u]) if (vis[v] != vct) { vis[v] = vct; qu.push(v); ta += dsu[v]; } } ans[t] = -ta; for (int u : cv) g[u].clear(); } qry.clear(); ce.clear(); lt = i; } } for (int i = 1; i <= q; ++i) if (ans[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...