题意

题目链接

一张图,n个点,m条边,每个点有个权值x,x<=1e18。如果一条边的两个端点不一样,那么这条边是安全的,开始时所有边都是安全的。

现在有一个病毒y,病毒可以入侵任意的点,入侵一个点后的权值为(y^x)。

(S,y)表示病毒的权值为y,它只入侵了点集S中的点,整张图的边都是安全的。求出所有的(S,y)。

Sol

不算是特别难想的div2压轴题。。

题目中保证了任意两个节点互不相同,因此想让图不安全,对于$(A, x)$一定是存在 A内一点 ^ x = 与该点相邻点的权值

显然,对于每一条边我们可以求出对应的x。

刚开始我傻乎乎的以为任意两个节点之间对应的值都是不同的,但是这样肯定是错的

比如 101 ^ 1 = 100, 1011 ^ 1 = 1010

但就算有相同的也没关系。

考虑$x$的贡献,如果存在两个节点,假设其权值分别为a,b,满足a ^ x = b

那么该节点要么同时不出现,要么同时出现,也就相当于把这两个点看成了一个点

然后我在这里又掉了一次坑,题目中只是说了“刚开始是安全的”,我天真的以为是互不相同。。

这样的话,就有可能存在好多个点看成一个点的情况,直接用并查集维护即可

最终的答案 = $\sum_{k} 2^siz(k) + (2^k - cnt) * (2^n)$

cnt表示互不相同的x的数量

$siz(k)$表示把$x ^ k = y$的点全都缩起来后的总点数

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<map>
#include<vector>
#define Pair pair<int, int>
#define MP(x, y) make_pair(x, y)
#define fi first
#define se second
#define LL long long
using namespace std;
const int MAXN = 1e6 + , mod = 1e9 + ;
inline LL read() {
char c = getchar(); LL x = , f = ;
while(c < '' || c > '') {if(c == '-') f = -; c = getchar();}
while(c >= '' && c <= '') x = x * + c - '', c = getchar();
return x * f;
}
int N, M, fa[MAXN];
LL po[MAXN], c[MAXN], K;
map<LL, vector<Pair> >mp;
int find(int x) {
return fa[x] == x ? fa[x] : fa[x] = find(fa[x]);
}
main() {
N = read(); M = read(); K = read();
po[] = ;
for(int i = ; i <= N; i++) c[i] = read();
for(int i = ; i <= max((LL)N, K); i++) po[i] = (1ll * * po[i - ]) % mod;
for(int i = ; i <= M; i++) {
int x = read(), y = read();
mp[c[x] ^ c[y]].push_back(MP(x, y));
}
LL ans = ;
map<LL, vector<Pair> >::iterator it;
for(int i = ; i <= N; i++) fa[i] = i;
for(it = mp.begin(); it != mp.end(); it++) {
LL val = it -> first;
vector<Pair> now = it -> second;
vector<int> res;
for(int i = ; i < now.size(); i++) {
int fx = find(now[i].fi), fy = find(now[i].se);
res.push_back(fx); res.push_back(fy);
if(fx == fy) continue;
fa[fx] = fy;
}
for(int i = ; i < res.size(); i++) fa[res[i]] = res[i];
(ans += po[tot]) %= mod;
}
printf("%I64d", (ans + 1ll * (po[K] - mp.size()) * po[N] % mod) % mod);
return ;
}

cf1040E. Network Safety(并查集)的更多相关文章

  1. POJ 2236 Wireless Network(并查集)

    传送门  Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 24513   Accepted ...

  2. poj 2236:Wireless Network(并查集,提高题)

    Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 16065   Accepted: 677 ...

  3. POJ 2236 Wireless Network (并查集)

    Wireless Network 题目链接: http://acm.hust.edu.cn/vjudge/contest/123393#problem/A Description An earthqu ...

  4. POJ 2236:Wireless Network(并查集)

    Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 36363   Accepted: 150 ...

  5. POJ3694:Network(并查集+缩点+lca)

    Network Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 13172   Accepted: 4774 题目链接:htt ...

  6. Brain Network (easy)(并查集水题)

    G - Brain Network (easy) Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & ...

  7. 【POJ - 2236】Wireless Network (并查集)

    Wireless Network 这接翻译了 Descriptions 地震发生在东南亚.ACM(亚洲合作医疗团队)已经与膝上电脑建立了无线网络,但是一次意外的余震袭击,网络中的所有计算机都被打破了. ...

  8. Codeforces1023F Mobile Phone Network 【并查集】【最小生成树】

    题目大意: 给一些没安排权值的边和安排了权值的边,没被安排的边全要被选入最小生成树,问你最大能把它们的权值和安排成多少.题目分析:假设建好了树,那么树边与剩下的每一条边都能构成一个环,并且非树边的权值 ...

  9. POJ3694 Network - Tarjan + 并查集

    Description 给定$N$个点和 $M$条边的无向联通图, 有$Q$ 次操作, 连接两个点的边, 问每次操作后的图中有几个桥 Solution 首先Tarjan找出边双联通分量, 每个双联通分 ...

随机推荐

  1. [ural1132]Square Root(cipolla算法)

    题意:求${x^2} \equiv n\bmod p$ 解题关键: 定理:若$a$满足$w = {a^2} - n$是模$p$的二次非剩余,即,${x^2} = w\bmod p$无解,则${(a + ...

  2. 为组件设定UI

    -----------------siwuxie095                             工程名:CustomizeSwing 包名:com.siwuxie095.swing 类 ...

  3. 具体问题:Spring 事务的隔离性,并说说每个隔离性的区别

    使用步骤: 步骤一.在spring配置文件中引入<tx:>命名空间<beans xmlns="http://www.springframework.org/schema/b ...

  4. 关于java中的编码问题

    ok,今天搞了一天都在探索java字符的编码问题.十分头疼.最后终于得出几点: 1.网上有很多博客说判断一个String的编码的方法是通过如下代码;但其实这个代码完全是错的,用一种编码decode后, ...

  5. [CentOS7] vncviewer与windows之间的复制粘贴

    转载:https://my.oschina.net/seava/blog/226966 用VNC连接到Linux之后,最纠结的问题就是无法复制粘贴.其实很简单,在Linux里面,打开一个终端,然后输入 ...

  6. nodebrew

    创建: 2019/05/30 完成: 2019/05/30  安装  安装 curl -L git.io/nodebrew | perl - setup 更新nodebrew nodebrew sel ...

  7. C++的STL总结(2)

    紧接着上篇博客,把没总结全的继续补充. (13)set容器 set是用红黑树的平衡二叉索引树的数据结构来实现的,插入时,它会自动调节二叉树排列,把元素放到适合的位置,确保每个子树根节点的键值大于左子树 ...

  8. KONG -- 图形化管理(Kong Dashboard)

    前面安装的 KONG 的版本是社区版的 1.0.2,官方的 KONG Manager 好像只有企业版才提供.在 github 上找了一个开源的图形化管理应用 -- Kong Dashboard (ht ...

  9. spring使用redisTemplate

    连接工厂:spring data redis 2.0中提供了两种redis客户端实现 LettuceConnectionFactory JedisConnectionFactory 区别: Lettu ...

  10. Error: Attribute application@allowBackup value=(false) from AndroidManifest.xml:14:7-34 is also present at [:react-native-qq] AndroidManifest.xml:14:18-44 value=(true).

    解决方法: 修改文件: 在manifest标签中添加 xmlns:tools="http://schemas.android.com/tools" 在application标签中添 ...