CodeForces - 724G:Xor-matic Number of the Graph
两点之间的任意路径都可表示为 随便某一条路径xor任何多个环,
然后可以用线性基来做,这样不会重复的,
另外必须一位一位的处理,xor是不满足结合律的
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<vector>
#define MOD 1000000007
#define MAXN 100000+10
#define ll long long
#define pb push_back
#define ft first
#define sc second
#define mp make_pair
#define pil pair<int,ll>
using namespace std;
int n,m;
vector<pil> G[MAXN];
ll d[MAXN];
int pw[MAXN];
vector<ll> vs;
vector<int> node;
void dfs(int x,ll c){
d[x]=c;node.pb(x);
for(int i=;i<G[x].size();i++){
pil& t=G[x][i];
if(-!=d[t.ft]){vs.pb(d[x]^d[t.ft]^t.sc);}
else{dfs(t.ft,c^t.sc);}
}
}
ll a[];
ll ans;
ll solve(){
memset(a,,sizeof(a));
int cnt=;ll ret=;
for(int i=;i<vs.size();i++){
ll v=vs[i];
if(!v)continue;
for(int j=;j>=;j--){
if((v>>j)&){
if(!a[j]){
cnt++;
a[j]=v;
break;
}
else{
v^=a[j];
}
}
}
}
for(int k=;k<=;k++){
int t[]={};
for(int i=;i<node.size();i++){
t[(d[node[i]]>>k)&]++;
}
bool flag=;
for(int i=;i<=;i++){
if((a[i]>>k)&){
flag=;break;
}
}
ll tmp=;
if(!flag){
tmp+=(1LL*t[]*t[]%MOD*pw[cnt]%MOD);
tmp%=MOD;
tmp*=pw[k];
tmp%=MOD;
}
else{
tmp+=(1LL*t[]*(t[]-))/+(1LL*t[]*(t[]-))/+(1LL*t[]*t[]%MOD);
tmp%=MOD;
if(cnt)tmp*=pw[cnt-],tmp%=MOD;
tmp*=pw[k];
tmp%=MOD;
}
ret+=tmp;
ret%=MOD;
}
return ret;
}
int main()
{
// freopen("data.in","r",stdin);
pw[]=;
for(int i=;i<=;i++){
pw[i]=pw[i-]*%MOD;
}
scanf("%d%d",&n,&m);
int x,y;ll w;
for(int i=;i<=m;i++){
scanf("%d%d%lld",&x,&y,&w);
G[x].pb(mp(y,w));G[y].pb(mp(x,w));
}
memset(d,-,sizeof(d));
for(int i=;i<=n;i++){
if(-==d[i]){
vs.clear(),node.clear();
dfs(i,);
ans+=solve();
ans%=MOD;
}
}
printf("%lld\n",ans);
return ;
}
CodeForces - 724G:Xor-matic Number of the Graph的更多相关文章
- Codeforces 617E:XOR and Favorite Number(莫队算法)
http://codeforces.com/problemset/problem/617/E 题意:给出n个数,q个询问区间,问这个区间里面有多少个区间[i,j]可以使得ai^ai+1^...^aj ...
- Codeforces 242E:XOR on Segment(位上的线段树)
http://codeforces.com/problemset/problem/242/E 题意:给出初始n个数,还有m个操作,操作一种是区间求和,一种是区间xor x. 思路:昨天比赛出的一道类似 ...
- Codeforces D546:Soldier and Number Game
题目链接 输入t对数 a, b 求(b,a]内的每个数拆成素因子的个数和 这里每个数都可以写成素数的乘积,可以写成几个素数的和就有几个素因子,这里求的是(b,a]内的素因子和 思路: 素数的素因子个数 ...
- Codeforces 724 G Xor-matic Number of the Graph 线性基+DFS
G. Xor-matic Number of the Graph http://codeforces.com/problemset/problem/724/G 题意:给你一张无向图.定义一个无序三元组 ...
- 动手写个数字输入框1:input[type=number]的遗憾
前言 最近在用Polymer封装纯数字的输入框,开发过程中发现不少坑,也有很多值得研究的地方.本系列打算分4篇来叙述这段可歌可泣的踩坑经历: <动手写个数字输入框1:input[type=nu ...
- xtrabackup备份MySQL报错:InnoDB: Error number 24 means 'Too many open files'
xtrabackup备份MySQL报错:InnoDB: Error number 24 means 'Too many open files' 1.使用xtrabackup备份MySQL时出现如下报错 ...
- 第193天:js---Math+Error+Number+Object总结
一.Math 随机选取 //随机选取 function getRandom (begin,end){ return Math.floor(Math.random()*(end-begin))+begi ...
- 【POI】导出xls文件报错:The maximum number of cell styles was exceeded. You can define up to 4000 styles in a .xls workbook
使用POI导出xls文件,由于数据过多,导致导出xls报错如下: The maximum number of cell styles was exceeded. You can define up t ...
- oracle创建jobs定时任务报错:PLS-00306: wrong number or types of arguments in call to 'JOB'
原脚本: begin sys.dbms_job.submit(job => job, what => 'xxx;', ...
随机推荐
- C语言第一次博客作业—输入输出
一.PTA实验作业 题目1:7-3 温度转换 本题要求编写程序,计算华氏温度150°F对应的摄氏温度.计算公式:C=5×(F−32)/9,式中:C表示摄氏温度,F表示华氏温度,输出数据要求为整型. 1 ...
- 从0开始的LeetCode生活—461-Hamming Distance(汉明距离)
题目: The Hamming distance between two integers is the number of positions at which the corresponding ...
- 项目Alpha冲刺Day7
一.会议照片 二.项目进展 1.今日安排 今天都是课,主要就是用空闲时间熟悉一下框架使用以及继续进行框架搭建. 2.问题困难 前台界面框架vue和element-ui的写法要适应. 3.心得体会 vu ...
- django搭建web (三) admin.py -- 待续
demo 关于模型myQuestion,myAnswer将在后述博客提及 # -*- coding: utf-8 -*- from __future__ import unicode_literals ...
- 【iOS】Swift if let 和 if var
if let unwrappedOptional = postDict { print("The optional has a value! It's \(unwrappedOptional ...
- bzoj千题计划219:bzoj1568: [JSOI2008]Blue Mary开公司
http://www.lydsy.com/JudgeOnline/problem.php?id=1568 写多了就觉着水了... #include<cstdio> #include< ...
- day-5 python协程与I/O编程深入浅出
基于python编程语言环境,重新学习了一遍操作系统IO编程基本知识,同时也学习了什么是协程,通过实际编程,了解进程+协程的优势. 一.python协程编程实现 1. 什么是协程(以下内容来自维基百 ...
- HTML5 拖放(Drag 和 Drop)详解与实例(转)
公司要开一个技术分享会,给我们出了几个简单的题去实现,其中有如何实现表格中列之间的拖拽,我知道html5中有个新方法可以实现,但是没有认真学习,现在闲了去学学,发现关于drag和drop的文章有很多, ...
- hadoop2.6.0实践:002 检查伪分布式环境搭建
1.检查网络配置[root@hadoop-master ~]# cat /etc/sysconfig/networkNETWORKING=yesHOSTNAME=hadoop-masterGATEWA ...
- Spring之AOP编程
一.AOP简介 AOP的英文全称是Aspect Oriented Programming,意为:面向切面编程. AOP采取横向抽取的机制,取代了传统纵向继承体系的代码复用.AOP常用于 ...