目录

题目链接

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;
}

CF1039C.Network Safety的更多相关文章

  1. [Codeforces Round #507][Codeforces 1039C/1040E. Network Safety]

    题目链接:1039C - Network Safety/1040E - Network Safety 题目大意:不得不说这场比赛的题面真的是又臭又长...... 有n个点,m条边,每个点有对应的权值c ...

  2. Codeforces.1040E.Network Safety(思路 并查集)

    题目链接 \(Description\) 有一张\(n\)个点\(m\)条边的无向图,每个点有点权.图是安全的当且仅当所有边的两个端点权值不同.保证初始时图是安全的. 现在有权值为\(x\)的病毒,若 ...

  3. cf1040E. Network Safety(并查集)

    题意 题目链接 一张图,n个点,m条边,每个点有个权值x,x<=1e18.如果一条边的两个端点不一样,那么这条边是安全的,开始时所有边都是安全的. 现在有一个病毒y,病毒可以入侵任意的点,入侵一 ...

  4. CCPC-Wannafly Summer Camp 2019 Day1

    A - Jzzhu and Cities CodeForces - 449B 题意:n座城市,m条路,k条铁路啥的吧,然后要求最多能删多少条铁路保持1到$n$的最短路不变. 思路:因为铁路是从1出发的 ...

  5. Improving the Safety, Scalability, and Efficiency of Network Function State Transfers

    Improving the Safety, Scalability, and Efficiency of Network Function State Transfers 来源:ACM SIGCOMM ...

  6. POJ 1966 Cable TV Network

    Cable TV Network Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 4702   Accepted: 2173 ...

  7. 【Network】Calico, Flannel, Weave and Docker Overlay Network 各种网络模型之间的区别

    From the previous posts, I have analysed 4 different Docker multi-host network solutions - Calico, F ...

  8. Java Concurrency In Practice -Chapter 2 Thread Safety

    Writing thread-safe code is managing access to state and in particular to shared, mutable state. Obj ...

  9. POJ 1966 Cable TV Network(顶点连通度的求解)

                               Cable TV Network Time Limit: 1000MS   Memory Limit: 30000K Total Submissi ...

随机推荐

  1. Linux内核驱动基础(一)常用宏定义【转】

    转自:http://blog.csdn.net/tommy_wxie/article/details/9427081 一: __init和__initdata  : __exit和__exitdata ...

  2. mac安装pyspider报错

    (env)$ pip3 uninstall pycurl (env)$ pip3 install --upgrade pip (env)$ export LDFLAGS=-L/usr/local/op ...

  3. 信息检索(IR)的评价指标介绍 - 准确率、召回率、F1、mAP、ROC、AUC

    原文地址:http://blog.csdn.net/pkueecser/article/details/8229166 在信息检索.分类体系中,有一系列的指标,搞清楚这些指标对于评价检索和分类性能非常 ...

  4. 016_nginx运维问题总结

    一.关于nginx请求包过大的解决思路 message-api.jyall.me.conf nginx报错问题问题定位,经分析跟接入navigator后关联不大,可参考一下结论连接超时抓包分析了一下每 ...

  5. 02-第一个JavaScript代码

    在页面中,我们可以在body标签中放入<script type=”text/javascript”></script>标签对儿,<script type=”text/ja ...

  6. 转:MySQL如何修改密码

    转:https://www.cnblogs.com/yang82/p/7794712.html. 第一种方式: 最简单的方法就是借助第三方工具Navicat for MySQL来修改,方法如下: 1. ...

  7. Oracle11g_OCM 课堂教学目录表

    注:本文为原著(其内容来自 腾科教育培训课堂).阅读本文注意事项如下: 1:所有文章的转载请标注本文出处. 2:本文非本人不得用于商业用途.违者将承当相应法律责任. 3:该系列文章目录列表: 一:&l ...

  8. 用javascript判断当前是安卓平台还是ios平台

    通常判断运行环境都是通过navigator.userAgent if (/android/gi.test(navigator.userAgent)){ // todo : android} if (/ ...

  9. linux 创建用户和密码

    :useradd -m 用户名//添加用户 :passwd 用户名 //然后设置密码 :userdel -r newuser1 //删除用户 newuser1,同时删除其自家目录 samba 设置账号 ...

  10. python+selenium五:多窗口切换与获取句柄

    from selenium import webdriverfrom selenium.webdriver.common.by import Byimport time driver = webdri ...