博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Bzoj1123 Blockade
阅读量:4633 次
发布时间:2019-06-09

本文共 1438 字,大约阅读时间需要 4 分钟。

题目链接:


日常水题,题目中已经给出了算法,写个模板即可,不会割点的这里有一篇博客:

难点是每个对可以互换顺序,然后删掉一个点之后它与其他所有点的对都会少1

下面给出代码:

#include
#include
#include
#include
#include
#include
#include
using namespace std;inline int rd(){ int x=0,f=1; char ch=getchar(); for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-1; for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0'; return x*f;}inline void write(long long x){ if(x<0) putchar('-'),x=-x; if(x>9) write(x/10); putchar(x%10+'0'); return ;}int n,m;int head[1000006],nxt[1000006],to[1000006];int total=0;void add(int x,int y){ total++; to[total]=y; nxt[total]=head[x]; head[x]=total; return ;}int tot=0;int dfn[1000006],low[1000006],book[1000006];int q[1000006],l=0,r=0;int size[1000006];long long ans[1000006];void Tarjan(int x){ int sum=0; size[x]=1; dfn[x]=low[x]=++tot; for(int e=head[x];e;e=nxt[e]){ if(!dfn[to[e]]){ Tarjan(to[e]); low[x]=min(low[x],low[to[e]]); size[x]+=size[to[e]]; if(low[to[e]]>=dfn[x]){ ans[x]+=(long long)sum*(long long)size[to[e]]; sum+=size[to[e]]; } } else low[x]=min(low[x],dfn[to[e]]); } ans[x]+=(long long)sum*(long long)(n-sum-1); return ;}int main(){ n=rd(),m=rd(); for(int i=1;i<=m;i++){ int x=rd(),y=rd(); add(x,y),add(y,x); } for(int i=1;i<=n;i++) if(!dfn[i]) Tarjan(i); for(int i=1;i<=n;i++) write((ans[i]+n-1)*2),puts(""); return 0;}

 

转载于:https://www.cnblogs.com/WWHHTT/p/9832540.html

你可能感兴趣的文章
poj2135最小费用最大流经典模板题
查看>>
hdu 4355 Party All the Time (2012 Multi-University Training Contest 6 ) 三分搜索
查看>>
POJ 2528 Mayor's posters(线段树)
查看>>
【转】[退役]纪念我的ACM——headacher@XDU
查看>>
利用STl实现队列
查看>>
android中The connection to adb is down,问题和解决 AndroidEclipseAntXML
查看>>
项目需求分析与建议
查看>>
UVa 10112 - Myacm Triangles
查看>>
给同一个按钮添加单双击事件
查看>>
form
查看>>
powershell输出错误信息到文件
查看>>
VS不显示最近打开的项目
查看>>
wcf客户端捕获异常
查看>>
MyEclipse安装Freemarker插件
查看>>
计算多项式的值
查看>>
DP(动态规划)
查看>>
chkconfig
查看>>
day44前端开发1之html基础
查看>>
小甲鱼-004改进小游戏
查看>>
琐碎的思绪
查看>>