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. Python日志记录(logging)

    import logging logfile = 'e:\\a.txt' # logging.basicConfig(filename=logfile,level=logging.INFO) # lo ...

  2. QT的时区转换以及使用注意事项

    QDateTime localDate = QDateTime::fromString("2018-12-11 10:40:00", "yyyy-MM-dd hh:mm: ...

  3. Linux chkconfig命令详解

    chkconfig命令检查.设置系统的各种服务.这是Red Hat公司遵循GPL规则所开发的程序,它可查询操作系统在每一个执行等级中会执行哪些系统服务,其中包括各类常驻服务.谨记chkconfig不是 ...

  4. Linux file命令详解

    file: 查看文件类型 file常见命令参数 Usage: file [OPTION...] [FILE...] Determine type of FILEs. --help display th ...

  5. 树&二叉树&&满二叉树&&完全二叉树&&完满二叉树

    目录 树 二叉树 完美二叉树(又名满二叉树)(Perfect Binary Tree) 完全二叉树(Complete Binary Tree) 完满二叉树(Full Binary Tree) 树 名称 ...

  6. 如何让邮件营销平台成为EDM神器?

    任何一家做邮件营销的企业都希望自己的投入获得超乎想象的回报,出现打开率.点击率和伴随而来的成交量能够节节攀升的现象,这些数据我们当然可以通过监测各种平台的反馈而得到确切的报表.当然,作为邮件营销平台运 ...

  7. [错误记录]python requests库 Response 判断坑

    在requests访问之后, 我直接判断resp的值, 如下: if resp: do something 发现当Response 为500的时候没有进入if分支, 检查源码,发现Response重写 ...

  8. 【问题记录】uwsgi部署并启动俩个几乎一样的python flask web app,发现有一个app响应时间非常长

    uwsgi在同一台linux上启动python flask web app(俩个), 发现第一个和第二个的简单性能测试差距非常大,差了将近一倍: 第一个结果: Concurrency Level: 1 ...

  9. python第一课——关于python的一些概念

    day01(上午): 1.学习方法(建议): 1).不要依赖于我的视频,绝对不要晚上将视频全部在过一遍 2).上课不要记笔记,而且不要用纸质的笔记本去整理笔记 3).不要只看不敲,代码方面我们需要做到 ...

  10. httpd:RSA certificate configured for SERVER does NOT include an ID which matches the server name

    这个是因为ssl认证丢失了密钥的问题,Apache的默认配置文件加载了mod_ssl模块,而且指定密钥对儿的位置,就是我测试salt-api时创建密钥对儿的位置.而且还有一个错误就是我密钥对儿指定的h ...