欢迎光临
我们一直在努力

PLCT检查是什么[LCT刷题][边双缩点] P2542 [AHOI2005] 航线规划

#include <bits/stdc++.h>
#pragma gcc optimize("O2")
#pragma g++ optimize("O2")
#define int long long
#define endl ' '
using namespace std;

const int N = 2e5 + 10, MOD = 1e9 + 7;

struct UnionFind {
std::vector<int> par, rank, size;
int c;
UnionFind(int n) : par(n), rank(n, 0), size(n, 1), c(n) {
for(int i = 0; i < n; ++i) par[i] = i;
}
int find(int i) { return (par[i] == i ? i : (par[i] = find(par[i]))); }
void merge(int u, int v)
};

UnionFind uf(1);

namespace LCT{
int ch[N][2], f[N], tag[N], siz[N];

#define ls ch[x][0]
#define rs ch[x][1]

inline void push_reverse(int x) { swap(ls, rs), tag[x] ^= 1; }

inline void push_down(int x)
}

void cleanch(int x) { ch[x][0] = ch[x][1] = f[x] = tag[x] = siz[x] = 0; }

inline void push_up(int x) { cleanch(0), siz[x] = siz[ls] + siz[rs] + 1; }

#define get(x) (ch[uf.find(f[x])][1] == x)
#define isRoot(x) (ch[uf.find(f[x])][0] != x && ch[uf.find(f[x])][1] != x)

void rotate(int x)

void update(int x)

void splay(int x)
push_up(x);
}

int access(int x) {
int p;
for(p = 0; x; x = uf.find(f[p = x])) splay(x), rs = p, push_up(x);
return p;
}

void makeRoot(int x) { access(x), splay(x), push_reverse(x); }

int findRoot(int x) {
access(x), splay(x);
while(ch[x][0]) push_down(x), x = ch[x][0];
splay(x);
return x;
}

void split(int x, int y) {
makeRoot(x);
access(y), splay(y);
}

void link(int x, int y)
}

#define pii pair<int, int>
#define fir first
#define sec second
vector<int> g[N];
map<pii, int> mp;

struct query{
int op, u, v;
}q[N];

vector<int> ans;

void merge_link(int u)

inline void solve(){
int n = 0, m = 0; cin >> n >> m;
for(int i = 1; i <= m; i++) {
int u, v; cin >> u >> v;
mp[{u, v}] = mp[{v, u}] = 1;
}
uf = UnionFind(n + 5);
int op_cnt = 0;
while(cin >> q[++op_cnt].op)
int opu, opv; cin >> opu >> opv;
q[op_cnt].u = opu, q[op_cnt].v = opv;
if(!q[op_cnt].op) mp[{opu, opv}] = mp[{opv, opu}] = 0;
}
reverse(q + 1, q + 1 + op_cnt);
for(auto &[edge, state] : mp) ] = 0;
int ufa = uf.find(edge.fir), vfa = uf.find(edge.sec);
if(LCT::findRoot(ufa) != LCT::findRoot(vfa)) LCT::link(ufa, vfa);
else
}
for(int i = 1; i <= op_cnt; i++) else {
ans.emplace_back(LCT::siz[vfa] - 1);
}
}
reverse(ans.begin(), ans.end());
for(auto v : ans) cout << v << endl;

}

signed main()
赞(0)
未经允许不得转载:上海聚慕医疗器械有限公司 » PLCT检查是什么[LCT刷题][边双缩点] P2542 [AHOI2005] 航线规划

登录

找回密码

注册