Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) G - Xor-matic Number of the Graph 线性基好题
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 线性基好题的更多相关文章
- 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的数组, ...
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)D Dense Subsequence
传送门:D Dense Subsequence 题意:输入一个m,然后输入一个字符串,从字符串中取出一些字符组成一个串,要求满足:在任意长度为m的区间内都至少有一个字符被取到,找出所有可能性中字典序最 ...
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) B. Batch Sort
链接 题意:输入n,m,表示一个n行m列的矩阵,每一行数字都是1-m,顺序可能是乱的,每一行可以交换任意2个数的位置,并且可以交换任意2列的所有数 问是否可以使每一行严格递增 思路:暴力枚举所有可能的 ...
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) C. Ray Tracing
我不告诉你这个链接是什么 分析:模拟可以过,但是好烦啊..不会写.还有一个扩展欧几里得的方法,见下: 假设光线没有反射,而是对应的感应器镜面对称了一下的话 左下角红色的地方是原始的的方格,剩下的三个格 ...
- 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个点,求射 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- intellij 插件结构(文件结构以及概念层面上的结构)
1.插件内的文件 2.插件类加载器 3.插件组件(component) 4.插件的扩展以及扩展点(Extensions.Extension Points) 5.插件的Action 6.插件的Servi ...
- springboot读取自己定义的配置文件的方式以及使用joda_time来处理时间日期
总的来说呢,有两种方式,一种是原始的方式,即使用PropertiesUtils来读取配置文件. 第二种就是使用springboot的注解的方式来读取配置文件. 1.原始方式处理属性和时间日期: 工具类 ...
- windows环境下封装条件wait和signal
linux 环境有提供好的pthread_cond_wait() 和 phread_signal().pthread_broadcast() windows需要自己封装,利用semophore控制线程 ...
- php 三元运算符简洁用法
<?php header('Content-type:text;charset=utf8'); $a = 'aaaa'; $b = $a ?:'; $c = $a ? $a : '; //这个和 ...
- 「Python」5个开源项目
1-OpenAI universe Universe是一个能在世界上所有的游戏.网站和其他应用中,衡量和训练AI通用智能的软件平台. Universe,AI代理通过称为虚拟网络计算或VNC发送模拟的鼠 ...
- 使用cron命令配置定时任务(cron jobs)
原文 http://www.cnblogs.com/end/archive/2012/02/21/2361741.html 开机就启动cron进程的设置命令:chkconfig --add crond ...
- 前端PHP入门-002-安装WAMP的集成环境md
> 第一次讲PHP,让我感觉还是满好玩的,一种新的知识的学习,需要我们努力! > 这次PHP课程计划是15天快速入门的课程! 只是单独的讲PHP语言,不涉及很深的内容,只是想让web前端的 ...
- git安装和简单配置
http://pan.baidu.com/share/link?shareid=4291215660&uk=219947478 直接贴网盘的地址了
- poi对excel的操作(二)
二.进阶的对象 1.CellType 枚举类 单元格类型 CellType.STRING---文本型 等 如何是指单元格类型:cell.setCellType(CellType.STRING) 2.C ...
- Bzoj2300 / 洛谷P2521 [HAOI2011]防线修建
题目描述 近来A国和B国的矛盾激化,为了预防不测,A国准备修建一条长长的防线,当然修建防线的话,肯定要把需要保护的城市修在防线内部了.可是A国上层现在还犹豫不决,到底该把哪些城市作为保护对象呢?又由于 ...