线性基板子

 1 struct DSU
 2 {
 3     int fa[MAXN];
 4     vector<int> base[MAXN];
 5     void add(int tar,int x)
 6     {
 7         for(auto &t:base[tar])
 8             x=min(x,x^t);
 9         if(!x)return;
10         for(auto &t:base[tar])
11             t=min(t,t^x);
12         base[tar].push_back(x);
13     }
14     int query(int tar)
15     {
16         int res=0;
17         for(auto &t:base[tar])
18             res=max(res,res^t);
19         return res;
20     }
21     void init(int n)
22     {
23         for(int i=1;i<=n;i++)
24             fa[i]=i,add(i,a[i]);
25     }
26     int find(int x)
27     {
28         return fa[x]==x ? x : fa[x]=find(fa[x]);
29     }
30     void merge(int x,int y)
31     {
32         x=find(x),y=find(y);
33         if(x==y)return;
34         fa[x]=y;
35         for(auto &v:base[x])add(y,v);
36         base[x].clear();
37     }
38     int answer(int x)
39     {
40         x=find(x);
41         return query(x);
42     }
43 }dsu;

 

转载于:https://www.cnblogs.com/CJLHY/p/8907559.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值