目录

题目链接

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. C++获取当前所有进程的完整路径

    实现代码 #include <stdio.h> #include <windows.h> #include <tlhelp32.h> #include <st ...

  2. L0/L1/L2范数(转载)

    一.首先说一下范数的概念: 向量的范数可以简单形象的理解为向量的长度,或者向量到零点的距离,或者相应的两个点之间的距离. 向量的范数定义:向量的范数是一个函数||x||,满足非负性||x|| > ...

  3. ARMV8 datasheet学习笔记4:AArch64系统级体系结构之编程模型(1)-EL/ET/ST

    1.前言 ARMV8系统级编程模型主要包括异常级别.运行状态.安全状态.同步异常.异步异常.DEBUG 本文主要对系统级编程模型做一个概要介绍 2. 异常级别 2.1 Exception level概 ...

  4. Linux性能分析的前60000毫秒【转】

    Linux性能分析的前60000毫秒 为了解决性能问题,你登入了一台Linux服务器,在最开始的一分钟内需要查看什么? 在Netflix我们有一个庞大的EC2 Linux集群,还有非常多的性能分析工具 ...

  5. python脚本发送邮件

    #!/usr/bin/python #_*_ coding:utf-8 _*_ from email.MIMEText import MIMEText from email.MIMEMultipart ...

  6. Vue.js——常用的指令

    1.v-on:指令监听DOM事件,并在触发时运行一些javaScript代码. <div id='myView'> <img src="img/se.png" v ...

  7. Python-CSS 基础

    css入门 一.架构分析 页面 => div的层级结构 => 具有采用哪些功能标签显示内容 结构层 > 位置层(布局层) > 内容层 二.css引入 - 行间式 <div ...

  8. PYTHON-匿名函数,递归与二分法,面向过程编程-练习

    # 四 声明式编程练习题 # 1.将names=['egon','alex_sb','wupeiqi','yuanhao']中的名字全部变大写names = ['egon', 'alex_sb', ' ...

  9. python与redis

    1.什么是redis Redis 是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合).zset ...

  10. 前端工程化-webpack(babel编译ES6)

    最新版安装与普通安装 使用babel-loader编译ES6,需要遵循规范,安装babel-presets 规范列表 对应babel-loader,babel-preset安装最新版和普通版: pre ...