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 ...
随机推荐
- 5.1 stack,queue以及priority_queue
*:stack 使用要包含头文件stack,栈是一种先进后出的元素序列,删除和访问只能对栈顶的元素(最后一个添加的元素)进行,并且添加元素只能添加到栈顶.栈内的元素不能访问,要想访问先要删除其上方的所 ...
- Smarty模板技术学习
模板引擎技术:使得php代码和html代码分离的技术就称为"模板引擎技术" 自定义smarty模板技术实现 <?php //迷你smarty原理 class MiniSmar ...
- 四、优化及调试--网站优化--Yahoo军规下
21.根据域名划分页面内容 很显然, 是最大限度地实现平行下载 22.尽量减少iframe的个数 考虑即使内容为空,加载也需要时间,会阻止页面加载,没有语意,注意iframe相对于其他DOM元素高出1 ...
- mysql常用表/视图管理语句
查看所有表 show tables; 查看表/视图结构 desc 表名/视图名: 查看建表过程 show create table 表名: 查看建视图过程 show create view 视图名 ...
- 【JAVA多线程概述】
一.多线程概述 一个进程中至少有一个线程,每一个线程都有自己运行的内容,这个内容可以称为线程要执行的任务. 不能没一个问题都使用多线程,能使用单线程解决的问题就不要使用多线程解决. 使用多线程的弊端: ...
- [LeetCode] Search Insert Position
Given a sorted array and a target value, return the index if the target is found. If not, return the ...
- Oracle数据库 控制文件
一.概念控制文件的主要任务是管理数据库的状态以及描述数据库的物理结构 二.所含有的信息1.数据库名2.数据库标识符(DBID)3.数据库创建时间戳4.数据库字符集5.数据文件信息6.临时文件信息7.在 ...
- css 妙味 总结
技巧一: <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF- ...
- SSH Key连接github提示Permission denied (publickey).错误
root@debian64:/home/xiaoliuzi/.ssh/key_backup# ssh -T git@github.com The authenticity of host 'githu ...
- OpenMesh 删除网格顶点
OpenMesh 提供了 delete_vertex() 函数来实现从网格中删除顶点,在删除掉顶点的同时,所有与该顶点相连的边也同时被删除. OpenMesh 官方文档 中给的顶点删除函数声明如下: ...