G - Xor-matic Number of the Graph

上一道题的加强版本,对于每个联通块需要按位算贡献。

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PII pair<int, int>
#define PLI pair<LL, int>
#define ull unsigned long long
using namespace std; const int N = 1e5 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ; int n, m;
LL d[N], bin[N], num[];
bool vis[N];
vector<PLI> edge[N];
vector<int> id;
struct Base {
LL a[];
int cnt;
void init() {
memset(a, , sizeof(a));
cnt = ;
}
void add(LL x) {
for(int j = ; ~j; j--) {
if((x >> j) & ) {
if(!a[j]) {a[j]=x; cnt++; break;}
else x ^= a[j];
}
}
}
} base; void dfs(int u, int fa) {
vis[u] = true;
id.push_back(u);
for(int i = ; i < edge[u].size(); i++) {
int v = edge[u][i].se; LL w = edge[u][i].fi;
if(v == fa) continue;
if(vis[v]) {
base.add(d[u]^d[v]^w);
} else {
d[v] = d[u] ^ w;
dfs(v, u);
}
}
} int main() {
base.pirnt();
scanf("%d%d", &n, &m);
for(int i=bin[]=; i <= n; i++)
bin[i] = bin[i-] * % mod;
for(int i = ; i <= m; i++) {
int u, v; LL w;
scanf("%d%d%lld", &u, &v, &w);
edge[u].push_back(mk(w, v));
edge[v].push_back(mk(w, u));
} LL ans = ;
for(int i = ; i <= n; i++) {
if(!vis[i]) {
base.init();
id.clear();
dfs(i, );
for(int j = ; j <= ; j++) {
num[] = , num[] = ;
for(auto &x : id) {
num[(d[x]>>j)&]++;
}
bool flag = false;
for(int k = ; k < ; k++) {
if((base.a[k]>>j)&) {
flag = true;
break;
}
} LL tmp = num[]*(num[]-)/ + num[]*(num[]-)/;
tmp %= mod;
if(flag) ans = (ans + bin[j]*bin[base.cnt-]%mod*tmp%mod) % mod;
tmp = num[] * num[] % mod;
if(flag) ans = (ans + bin[j]*bin[base.cnt-]%mod*tmp%mod) % mod;
else ans = (ans + bin[j]*bin[base.cnt]%mod*tmp%mod) % mod;
}
}
}
printf("%lld\n", ans);
return ;
} /*
*/

Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) G - Xor-matic Number of the Graph 线性基好题的更多相关文章

  1. CF Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)

    1. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) B. Batch Sort    暴力枚举,水 1.题意:n*m的数组, ...

  2. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)D Dense Subsequence

    传送门:D Dense Subsequence 题意:输入一个m,然后输入一个字符串,从字符串中取出一些字符组成一个串,要求满足:在任意长度为m的区间内都至少有一个字符被取到,找出所有可能性中字典序最 ...

  3. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) B. Batch Sort

    链接 题意:输入n,m,表示一个n行m列的矩阵,每一行数字都是1-m,顺序可能是乱的,每一行可以交换任意2个数的位置,并且可以交换任意2列的所有数 问是否可以使每一行严格递增 思路:暴力枚举所有可能的 ...

  4. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) C. Ray Tracing

    我不告诉你这个链接是什么 分析:模拟可以过,但是好烦啊..不会写.还有一个扩展欧几里得的方法,见下: 假设光线没有反射,而是对应的感应器镜面对称了一下的话 左下角红色的地方是原始的的方格,剩下的三个格 ...

  5. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) C.Ray Tracing (模拟或扩展欧几里得)

    http://codeforces.com/contest/724/problem/C 题目大意: 在一个n*m的盒子里,从(0,0)射出一条每秒位移为(1,1)的射线,遵从反射定律,给出k个点,求射 ...

  6. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) E. Goods transportation (非官方贪心解法)

    题目链接:http://codeforces.com/contest/724/problem/E 题目大意: 有n个城市,每个城市有pi件商品,最多能出售si件商品,对于任意一队城市i,j,其中i&l ...

  7. Codeforces Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) A. Checking the Calendar(水题)

    传送门 Description You are given names of two days of the week. Please, determine whether it is possibl ...

  8. Codeforces Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) B. Batch Sort(暴力)

    传送门 Description You are given a table consisting of n rows and m columns. Numbers in each row form a ...

  9. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) B

    Description You are given a table consisting of n rows and m columns. Numbers in each row form a per ...

  10. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) A

    Description You are given names of two days of the week. Please, determine whether it is possible th ...

随机推荐

  1. bnuoj53075 外挂使用拒绝

    题目链接:http://www.bnuoj.com/v3/problem_show.php?pid=53075 第一次给校赛出题,来为自己的题目写一发题解吧. 其实我原本的题意非常简洁: 结果被另一位 ...

  2. 电商网站中价格的精确计算(使用BigDecimal进行精确运算(实现加减乘除运算))

    使用BigDecimal的String的构造器.商业计算中,使用bigdecimal的String构造器,一定要用. 重要的事情说三遍: 商业计算中,使用bigdecimal的String构造器! 商 ...

  3. sloop公共程序之初始过程及启动

    1:sloop_init() 初始化主要是初始化静态sloop_*** 结构体和填充struct sloop_data 结构体中的成员. //初始化静态存储区给sloop_***结构体 static ...

  4. mysql 自动记录数据最后修改时间

    原文 -- mysql ,还真有这样的说法: mysql> create table test( ), -> uptime timestamp on update current_time ...

  5. 10个有关String的面试问题

    下面是面试中最容易问到的有关String的问题. 1. 如何比较两个字符串?使用"=="还是equals()方法? 简单来讲,"=="测试的是两个对象的引用是否 ...

  6. No qualifying bean of type [java.lang.String] found for dependency: expected

    出现这个问题的原因是因为多写了一个注解但是没有实体类.如: 或者其他注解下没有内容.

  7. [Thu Summer Camp 2015]解密运算

    4104: [Thu Summer Camp 2015]解密运算 Time Limit: 10 Sec  Memory Limit: 512 MB Description 对于一个长度为N的字符串,我 ...

  8. 莫队+分块 BZOJ 3809

    3809: Gty的二逼妹子序列 Time Limit: 80 Sec  Memory Limit: 28 MBSubmit: 1634  Solved: 482[Submit][Status][Di ...

  9. 可编辑表格(Editable Table)

    需求分析 1.单击table的每个cell后,给cell加上一个尺寸相当的input; 2.input后把value传给cell的innerHTML; 3.失焦后删除input. HTML <! ...

  10. ② 设计模式的艺术-08.桥接(Bridge)模式

    为什么需要桥接(Bridge)模式 商城系统中常见的商品分类,以电脑为类,如何良好的处理商品分类销售的问题? 采用多层继承结构: 多层继承结构代码示例 Computer.java package co ...