目录

题目链接

CF1039C.Network Safety

题解

对于一对相邻点,^异或后相同的值唯一a_i ^ t= b_i,a_i ^ b_i = t

对于不在t集合的直接算上

对于t集合,对于每个t分别计算联块的个数,然后加上联通块子集个数

代码

#include<map>
#include<vector>
#include<cstdio>
#include<algorithm>
#define int long long
#define gc getchar()
#define pc putchar
inline int read() {
int x = 0,f = 1;
char c = gc;
while(c < '0' || c > '9')c = gc;
while(c <= '9' && c >= '0') x = x * 10 + c - '0',c = gc;
return x * f;
}
void print(int x) {
if(x < 0) {
pc('-');
x = -x;
}
if(x >= 10) print(x / 10);
pc(x % 10 + '0');
}
const int maxn = 1000007;
const int mod = 1e9 + 7;
#define LL long long
int n,m,k;
int a[maxn];
int p[maxn];
std::vector<int>v[maxn];
int id[maxn];
int bel[maxn];
int fa[maxn];
int find(int x) {
if(fa[x] != x) fa[x] = find(fa[x]);
return fa[x];
}
struct node {
int u,v;
} e[maxn << 1];
std::map<LL,int>mp;
main() {
int tot = 0;
n = read(), m = read() , k = read();
p[0] = 1;
for(int i = 1;i <= n;++ i) p[i] = p[i - 1] * 2 % mod;
for(int i = 1;i <= n;++ i) a[i] = read(),fa[i] = i;
for(int i = 1;i <= m;++ i) {
e[i].u = read(),e[i].v = read();
int t = a[e[i].u] ^ a[e[i].v];
if(!mp[t]) mp[t] = ++ tot;
id[++ tot] = t;
v[mp[t]].push_back(i);
}
int ans = 1ll * ((1ll << k) - tot) % mod * p[n] % mod;
for(int i = 1;i <= tot;++ i) {
int size = n;
for(int j = 0;j < v[i].size();++ j) {
int E = v[i][j];
int fx = find(e[E].u),fy = find(e[E].v);
if(fx != fy) {
fa[fx] = fy;
size --;
}
}
(ans += p[size]) %= mod;
for(int j = 0;j < v[i].size();++ j) {
int E = v[i][j];
fa[e[E].u] = e[E].u;
fa[e[E].v] = e[E].v;
}
}
print(ans);
pc('\n');
return 0;
}

最新文章

  1. 面试复习(C++)之直接选择排序
  2. word2vec使用说明补充(google工具包)
  3. 使用android ProgressBar和Toast生成一个界面
  4. mac 下安装android studio(转)
  5. linux性能监测与优化
  6. HLS入门收集(1)
  7. [.NET 4.5] ADO.NET / ASP.NET 使用 Async 和 Await 异步 存取数据库
  8. CListView虚拟列表
  9. Android开发之XML的创建和解析
  10. ReactEurope Conf 参会感想
  11. [转]PHP经验——PHPDoc PHP注释的标准文档
  12. Springboot的默认定时任务——Scheduled注解
  13. 亲密接触Redis-第二天(Redis Sentinel)
  14. [Swift]LeetCode743. 网络延迟时间 | Network Delay Time
  15. CSS3_标准盒子模型和怪异盒子模型
  16. SpringBoot 学习教程(二):示例
  17. 1.1.25 word图片批量对齐
  18. Windows系统中设置Python程序定时运行方法
  19. 关于php laravel5.1框架出现路由找不到的情况
  20. centos7 php性能调优

热门文章

  1. CMake 示例
  2. OA协同办公软件
  3. springboot系列八、springboot整合kafka
  4. rsync同步(winxdows到linux/linux到linxu同步)
  5. C# 将任意对象快速转换为Json
  6. C++:MSVCRTD.lib(crtexe.obj) : error LNK2019: 无法解析的外部符号 _main,该符号在函数 ___tmainCRTStart
  7. 基于Apache的阿里云部署Node.js服务器(Windows环境)
  8. 石头剪刀布三局两胜(平局重来break用法)
  9. css3图片旋转
  10. 性能测试四:jmeter进阶之逻辑控制器