codeforces 1040E. Network Safety

题目:http://codeforces.com/contest/1040/problem/E

思路:

若x,y之间有一条边,权值分别为a[x],a[y], 设t=a[x]^a[y],

则只有a[x]^t==a[y],a[y]^t==a[x],因此只有其中一个数

异或上t才是不安全的,两个数都异或上t则相当于交换

x,y。可以按0~(1<

x,y两个点看作了一个(要么都不异或t,要么都异或t)

对于固定的t,只要有边相连的就缩成一个点即可。

因为边最多有5e5条,因此t最多有5e5个取值,

对于其余的t统一处理即可。

代码:

#include
using namespace std;
#define ll long long
const int maxn=5e5+10;
const ll mod=1e9+7;
struct node
{
    int x,y;
};
vectorG[maxn*2];
mapmp;
int tol,par[maxn];
ll a[maxn],power[maxn];
int Find(int x)
{
    if(x==par[x]) return x;
    return par[x]=Find(par[x]);
}
void unite(int x,int y)
{
    x=Find(x);y=Find(y);
    if(x!=y) par[x]=y;
}
int main()
{
    power[0]=1;
    for(int i=1;i

 

你可能感兴趣的:(codeforces)