BZOJ1315 : Ural1557Network Attack
找到一棵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的更多相关文章
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- 【Cocos2d-x for WP8 学习整理】(2)Cocos2d-Html5 游戏 《Fruit Attack》 WP8移植版 开源
这一阵花了些时间,把 cocos2d-html5 里的sample 游戏<Fruit Attack>给移植到了WP8上来,目前已经实现了基本的功能,但是还有几个已知的bug,比如WP8只支 ...
- Web 服务器 low bandth DOS attack
https://www.owasp.org/images/0/04/Roberto_Suggi_Liverani_OWASPNZDAY2010-Defending_against_applicatio ...
- CF 701B Cells Not Under Attack(想法题)
题目链接: 传送门 Cells Not Under Attack time limit per test:2 second memory limit per test:256 megabyte ...
- ASP.NET Padding Oracle Attack EXP
#!/usr/bin/perl## PadBuster v0.3 - Automated script for performing Padding Oracle attacks# Brian Hol ...
- 人机接口设备攻击(HID Attack)
人机接口设备攻击(HID Attack) HID Attack是最近几年流行的一类攻击方式.HID是Human Interface Device的缩写,意思是人机接口设备.它是对鼠标.键盘.游戏手 ...
- 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 ...
- 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 ...
- PHP filesystem attack vectors
http://www.ush.it/2009/02/08/php-filesystem-attack-vectors/ On Apr 07, 2008 I spoke with Kuza55 and ...
随机推荐
- ld: framework not found AGCommon 关于三方库到入 问题解决方案!!
ld: framework not found AGCommon clang:error:linker command failed with exit code 1 (use -v to see ...
- 使用DateUtils和DateFormatUtils处理时间日期转换与SimpleDateFormat的区别
在Apache Commons项目的Lang里面,有两个类:DateUtils和DateFormatUtils,专门用于处理时间日期转换.它们在 org.apache.commons.lang.tim ...
- iOS - 定制多样式二维码
二维码/条形码是按照某种特定的几何图形按一定规律在平台(一维/二维方向上)分布的黑白相间的图形纪录符号信息.使用若干个与二进制对应的几何形体来表示文字数值信息. 最常见的二维码功能包括信息获取.网 ...
- phpcms 标签
都说pc标签{pc:content参数名="参数值"参数名="参数值"参数名="参数值"} 但是 参数名对应的具体参数值有那些,菜鸟就不知道 ...
- mysqlbinlog 查看日志时发生报错
[root@cs Downloads]# mysqlbinlog mysql-bin. ERROR: Error , event_type: ERROR: Could not read entry a ...
- 关于v$datafile中system表空间的status值始终为system
http://docs.oracle.com/cd/B19306_01/server.102/b14237/dynviews_1076.htm#REFRN30050 http://blog.itpub ...
- Pyqt phonon的使用
本文是用Pyqt实现了下网上一个Qt版大牛关于phonon的介绍 Qt phonon地址:http://wenku.baidu.com/link?url=nH_dZ8lZbXHy8N5__8jAWLX ...
- 【翻译十二】java-并发之活性
A concurrent application's ability to execute in a timely manner is known as its liveness. This sect ...
- Ubuntu / Win7 安装db2 v10.5
抓紧下载v10.5fp1_linuxx64_expc.tar.gz到~/Downloads/java_softcd java_softtar xf v10.5fp1_linuxx64_expc.tar ...
- ASP.NET MVC 4 WebAPI Simple Sample
// Controllers.cs namespace Microshaoft.WebApi.Controllers { using Microshaoft.WebApi.Models; using ...