找到一棵dfs搜索树,给每条非树边一个随机非0权值,每条树边为所有经过它的树边的权值的异或。

那么有2种情况是合法的:

1.一条边权值为0,一条边权值非0。

2.两条边异或和为0。

排序后统计即可,时间复杂度$O(m\log m)$。

#include<cstdio>
#include<algorithm>
const int N=2010,M=100010;
int n,m,i,j,e[M][2],g[N],v[M<<1],w[M<<1],nxt[M<<1],ed,d[N],dfn,f[N],c0,c1;
unsigned long long seed,h[M],tag[N],ans;
inline void read(int&a){char c;while(!(((c=getchar())>='0')&&(c<='9')));a=c-'0';while(((c=getchar())>='0')&&(c<='9'))(a*=10)+=c-'0';}
inline void add(int x,int y,int z){v[++ed]=y;w[ed]=z;nxt[ed]=g[x];g[x]=ed;}
void dfs(int x){
d[x]=++dfn;
for(int i=g[x];i;i=nxt[i])if(w[i]!=f[x]){
int y=v[i];
if(d[y]&&d[y]<=d[x]){
for(seed=seed*233+17;!seed;seed=seed*233+17);
h[w[i]]=seed,tag[x]^=seed,tag[y]^=seed;
}else if(!d[y])f[y]=w[i],dfs(y);
}
}
void cal(int x){
for(int i=g[x];i;i=nxt[i])if(f[v[i]]==w[i]&&d[v[i]]>d[x])cal(v[i]),tag[x]^=tag[v[i]];
h[f[x]]=tag[x];
}
int main(){
read(n),read(m);
for(i=1;i<=m;i++)read(e[i][0]),read(e[i][1]),add(e[i][0],e[i][1],i),add(e[i][1],e[i][0],i);
dfs(1),cal(1);
for(i=1;i<=m;i++)if(h[i])c1++;else c0++;
ans=1ULL*c0*c1;
std::sort(h+1,h+m+1);
for(i=1;i<=m;i=j){
for(j=i;j<=m&&h[i]==h[j];j++);
ans+=1ULL*(j-i)*(j-i-1)/2;
}
return printf("%llu",ans),0;
}

  

BZOJ1315 : Ural1557Network Attack的更多相关文章

  1. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  2. 【Cocos2d-x for WP8 学习整理】(2)Cocos2d-Html5 游戏 《Fruit Attack》 WP8移植版 开源

    这一阵花了些时间,把 cocos2d-html5 里的sample 游戏<Fruit Attack>给移植到了WP8上来,目前已经实现了基本的功能,但是还有几个已知的bug,比如WP8只支 ...

  3. Web 服务器 low bandth DOS attack

    https://www.owasp.org/images/0/04/Roberto_Suggi_Liverani_OWASPNZDAY2010-Defending_against_applicatio ...

  4. CF 701B Cells Not Under Attack(想法题)

    题目链接: 传送门 Cells Not Under Attack time limit per test:2 second     memory limit per test:256 megabyte ...

  5. ASP.NET Padding Oracle Attack EXP

    #!/usr/bin/perl## PadBuster v0.3 - Automated script for performing Padding Oracle attacks# Brian Hol ...

  6. 人机接口设备攻击(HID Attack)

    人机接口设备攻击(HID Attack)   HID Attack是最近几年流行的一类攻击方式.HID是Human Interface Device的缩写,意思是人机接口设备.它是对鼠标.键盘.游戏手 ...

  7. Codeforces Round #364 (Div. 2) B. Cells Not Under Attack

    B. Cells Not Under Attack time limit per test 2 seconds memory limit per test 256 megabytes input st ...

  8. PHP filesystem attack vectors - Take Two

    http://www.ush.it/2009/07/26/php-filesystem-attack-vectors-take-two/ Did you enjoyed our previous &q ...

  9. PHP filesystem attack vectors

    http://www.ush.it/2009/02/08/php-filesystem-attack-vectors/ On Apr 07, 2008 I spoke with Kuza55 and ...

随机推荐

  1. hdu1115(计算多边形几何重心)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1115 题意:给出一些点,求这些点围成的多边形的重心: 思路: 方法1:直接分别求所有点的x坐标的平均值 ...

  2. 随机数组&大数相加

    随机生成10个数,填充一个数组,然后用消息框显示数组内容,接着计算数组元素的和,将结果也显示在消息框中 一,      设计思路: 先生成随机数数组,再将数组保存在一个字符串中,然后将数组各数字加和, ...

  3. windows服务 - C# U盘升级

    1.左侧工具栏里有Timer控件,但是如果调用的是系统时间,就需要添加System.timer.timer空间下的控件.   2.服务编写之后,还不能由SCM(服务控制管理器)进行管理,需要给该服务添 ...

  4. 13.代理模式(Proxy Pattern)

    using System; namespace Test { //抽象角色:声明真实对象和代理对象的共同接口. //代理角色:代理对象角色内部含有对真实对象的引用,从而可以操作真实对象, //同时代理 ...

  5. ReentrantLock和synchronized两种锁定机制

    ReentrantLock和synchronized两种锁定机制 >>应用synchronized同步锁 把代码块声明为 synchronized,使得该代码具有 原子性(atomicit ...

  6. python多进程程序之间交换数据的两种办法--Queue和Pipe

    合在一起作的测试. #!/usr/bin/env python # -*- coding: utf-8 -*- import multiprocessing import random import ...

  7. 无废话ExtJs 入门教程十三[上传图片:File]

    无废话ExtJs 入门教程十三[上传图片:File] extjs技术交流,欢迎加群(201926085) 1.代码如下: 1 <!DOCTYPE html PUBLIC "-//W3C ...

  8. Codeforces Round #363 Fix a Tree(树 拓扑排序)

    先做拓扑排序,再bfs处理 #include<cstdio> #include<iostream> #include<cstdlib> #include<cs ...

  9. Oracle优化 -- 关于Database Buffer Cache相关参数DB_CACHE_SIZE的优化设置

    select size_for_estimate, buffers_for_estimate ,ESTD_PHYSICAL_READ_factor,ESTD_PHYSICAL_READS from v ...

  10. C#交互功能的演化

    (此文章同时发表在本人微信公众号“dotNET每日精华文章”,欢迎右边二维码来关注.) 题记:Miguel de Icaza在最近发表的一篇博文中畅谈了Mono及其相关产品中的C#交互特性的演化情况. ...