G. Xor-matic Number of the Graph

链接

题意:

  给定一个无向图,一个interesting的三元环(u,v,s)满足,从u到v的路径上的异或和等于s,三元环的权值为s,求所有三元环权值之和。

分析:

  求出所有的三元环,建立线性基,然后逐位求每一位的贡献。

代码:

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
#include<cctype>
#include<set>
#include<queue>
#include<vector>
#include<map>
using namespace std;
typedef long long LL; inline LL read() {
LL x=,f=;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-;
for(;isdigit(ch);ch=getchar())x=x*+ch-'';return x*f;
} const int N = , mod = 1e9 + ;
struct Edge{ int to, nxt; LL w; } e[];
int head[N], En;
LL dis[N], b[], mi[N], Ans;
bool vis[N];
vector<LL> B;
vector<int> A; inline void add_edge() {
int u = read(), v = read(); LL w = read();
++En; e[En].to = v, e[En].w = w; e[En].nxt = head[u]; head[u] = En;
++En; e[En].to = u, e[En].w = w; e[En].nxt = head[v]; head[v] = En;
}
void dfs(int u) {
A.push_back(u);
vis[u] = ;
for (int i = head[u]; i; i = e[i].nxt) {
int v = e[i].to;
if (vis[v]) B.push_back(dis[u] ^ e[i].w ^ dis[v]);
else {
dis[v] = dis[u] ^ e[i].w;
dfs(v);
}
}
}
void Insert(LL x) {
for (int i = ; ~i; --i) {
if ((x >> i) & ) {
if (b[i]) x ^= b[i];
else {
b[i] = x;
break;
}
}
}
}
void Clear() {
memset(b, , sizeof(b));
A.clear(), B.clear();
}
inline void mul(LL &x,LL y) { x *= y; x %= mod; }
inline void add(LL &x,LL y) { x += y; if (x >= mod) x -= mod; } void Calc() {
for (int i = ; i < (int)B.size(); ++i) Insert(B[i]);
LL cnt[] = {, }, r = , now;
for (int i = ; ~i; --i) if (b[i]) r ++;
for (int k = ; ~k; --k) {
bool flag = ; cnt[] = cnt[] = ;
for (int i = ; ~i; --i) if ((b[i] >> k) & ) flag = ;
for (int i = ; i < (int)A.size(); ++i) cnt[(dis[A[i]] >> k) & ] ++;
now = cnt[] * (cnt[] - ) / + cnt[] * (cnt[] - ) / ; now %= mod;
if (flag) {
if (r >= ) mul(now, mi[r - ]);
mul(now, mi[k]);
add(Ans, now);
}
now = cnt[] * cnt[];
if (flag) { if (r >= ) mul(now, mi[r - ]); }
else mul(now, mi[r]);
mul(now, mi[k]);
add(Ans, now);
}
Clear();
} int main() {
int n = read(), m = read();
mi[] = ;
for (int i = ; i <= ; ++i) mi[i] = mi[i - ] * % mod;
for (int i = ; i <= m; ++i) add_edge();
for (int i = ; i <= n; ++i) {
if (!vis[i]) {
dfs(i);
Calc();
}
}
cout << Ans;
return ;
}

CF 724 G. Xor-matic Number of the Graph的更多相关文章

  1. Codeforces 724 G Xor-matic Number of the Graph 线性基+DFS

    G. Xor-matic Number of the Graph http://codeforces.com/problemset/problem/724/G 题意:给你一张无向图.定义一个无序三元组 ...

  2. 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 ...

  3. CF - 392 C. Yet Another Number Sequence (矩阵快速幂)

    CF - 392 C. Yet Another Number Sequence 题目传送门 这个题看了十几分钟直接看题解了,然后恍然大悟,发现纸笔难于描述于是乎用Tex把初始矩阵以及转移矩阵都敲了出来 ...

  4. 2019南昌网络赛G. tsy's number

    题意:\(\sum_{i=1}^n\sum_{j=1}^n\sum_{k=1}^n\frac{\phi(i)*\phi(j^2)*\phi(k^3)}{\phi(i)*\phi(j)*\phi(k)} ...

  5. CF 1051 G. Distinctification

    G. Distinctification 链接 分析: 线段树合并 + 并查集. 最后操作完后a连续递增的一段,b一定是递减的.最后的答案是$\sum (a_{new}-a_{odd}) \times ...

  6. CF 1093 G. Multidimensional Queries

    G. Multidimensional Queries 链接 分析: 考虑如何去掉绝对值符号. $\sum \limits_{i = 1}^{k} |a_{x, i} - a_{y, i}|$,由于k ...

  7. CF 914 G Sum the Fibonacci —— 子集卷积,FWT

    题目:http://codeforces.com/contest/914/problem/G 其实就是把各种都用子集卷积和FWT卷起来算即可: 注意乘 Fibonacci 数组的位置: 子集卷积时不能 ...

  8. 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 G. Xor

    There is a tree with nn nodes. For each node, there is an integer value a_ia​i​​, (1 \le a_i \le 1,0 ...

  9. CF 960 G

    难受的1b,怎么会这样 先去学写一发 NTT 大概说一下斯特林数

随机推荐

  1. [翻译] TCBlobDownload

    TCBlobDownload TCBlobDownload uses NSOperations to download large files (typically videos, music... ...

  2. Office 365实现单点登录系列(4)—安装AD FS

    单一登录 (Single Sign-On)简而言之,就是让用户使用一套ID和密码,就可以登录一个或多个系统的授权机制.用户只需要通过其中一个应用的安全认证之后,再访问同一服务器其他应用的资源时不需要再 ...

  3. Spring @Autowired注解在非Controller/Service中注入为null

    参考:https://blog.csdn.net/qq_35056292/article/details/78430777 问题出现: 在一个非controller/service类中,我需要注入Co ...

  4. 铁乐学python_day25_序列化模块

    铁乐学python_day25_序列化模块 部份内容摘自博客http://www.cnblogs.com/Eva-J/ 回顾内置方法: __len__ len(obj)的结果依赖于obj.__len_ ...

  5. matlab中关于函数句柄、feval函数以及inline函数的解析 (转)

    http://blog.sina.com.cn/s/blog_7bff755b010180l3.html MATLAB函数句柄 函数句柄(Function handle)是MATLAB的一种数据类型. ...

  6. Virtual PC局域网共享速度慢的解决半法。转

    HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\DisableTaskOffload 新建字符串,名:DisableTaskOffloa ...

  7. December 04th 2016 Week 50th Sunday

    Learn wisdom by the follies of others. 前车之鉴,后人之师. Maybe my personal state is that others can learn w ...

  8. codeforces 17D Notepad

    codeforces 17D Notepad 题意 题解 TBD 更新模板(phi.欧拉降幂) 代码 #include<bits/stdc++.h> using namespace std ...

  9. C++暑期学习笔记

    # C++初步学习笔记 一.命名空间(namespace)相关 1 个人理解: 为了避免整合资源中存在的重名矛盾而采取的区别资源的措施: 2 命名空间的定义: 比如要定义一个命名空间A: namesp ...

  10. 推荐一个好用的以多tab标签方式打开windows CMD的工具

    最近我在做基于nodejs的微服务开发,需要在windows命令行里启动很多微服务.我的windows 10任务栏是这样子的: 我想找一款能像下图Chrome标签页这样打开windows 10 CMD ...