传送门

分析

我们知道对于一个割点,我们如果去掉它就会使原来的图被分为若干块,则这是我们将所有块包含的点的个数两两相乘即可,而如果不是割点则对于图的连通性没有影响。注意在最后要加上2*(n-1)表示去掉的那个点对答案产生的贡献。

代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
long long dfn[],low[],cnt,sum,siz[];
long long ans[],n,m;
vector<long long>v[];
inline void tarjan(long long x,long long la){
siz[x]=;
dfn[x]=low[x]=++cnt;
long long son=,tot=;
for(long long i=;i<v[x].size();i++)
if(v[x][i]!=la){
if(!dfn[v[x][i]]){
son++;
tarjan(v[x][i],x);
siz[x]+=siz[v[x][i]];
low[x]=min(low[x],low[v[x][i]]);
if(dfn[x]<=low[v[x][i]]){
ans[x]+=siz[v[x][i]]*tot;
tot+=siz[v[x][i]];
}
}else low[x]=min(low[x],dfn[v[x][i]]);
}
ans[x]+=tot*(n-tot-);
if(son==&&!la)ans[x]=;
}
int main(){
long long i,j,k;
scanf("%lld%lld",&n,&m);
for(i=;i<=m;i++){
long long x,y;
scanf("%lld%lld",&x,&y);
v[x].push_back(y);
v[y].push_back(x);
}
for(i=;i<=n;i++)
if(!dfn[i])tarjan(i,);
for(i=;i<=n;i++)printf("%lld\n",(ans[i]+n-)*);
return ;
}

loj10104 [POI 2008]Blockade的更多相关文章

  1. [POI 2008&洛谷P3467]PLA-Postering 题解(单调栈)

    [POI 2008&洛谷P3467]PLA-Postering Description Byteburg市东边的建筑都是以旧结构形式建造的:建筑互相紧挨着,之间没有空间.它们共同形成了一条长长 ...

  2. [POI 2008]Mafia

    这题目写了我好长时间,但还是几乎(不要在意细节)一遍 A 了喵~ 据说有代码奇短的,Orz 思路巧妙的大爷 想我这种 Brute Force 写写的傻 X 真是代码量飞起来了耶,喵~ 如果把每个人看成 ...

  3. [POI 2008][BZOJ 1132]Tro

    这题我真是无能为力了 这题的做法还是挺简单的 枚举左下角的点做为原点,把其余点按极角排序    PS.是作为原点,如枚举到 k 时,对于所有 p[i] (包括p[k]) p[i]-=p[k] (此处为 ...

  4. bzoj 1112 poi 2008 砖块

    这滞胀题调了两天了... 好愚蠢的错误啊... 其实这道题思维比较简单,就是利用treap进行维护(有人说线段树好写,表示treap真心很模板) 就是枚举所有长度为k的区间,查出中位数,计算代价即可. ...

  5. 解题:POI 2008 Subdivision of Kingdom

    题面 还可以这么搜......学到了(PoPoQQQ orz) 我们最朴素的做法是枚举所有状态(当然可以剪,剪完最终实际状态量也是$C_{26}^{13}$的),然后每次$O(n)$扫一遍判断,大概会 ...

  6. 解题:POI 2008 Plot purchase

    题面 原来看过然后没做,结果板板把这道题改了改考掉了,血亏=.= 首先看看有没有符合条件的点.如果没有开始寻找解,先把所有的大于$2*k$的点设为坏点,然后求最大子矩形,只要一个最大子矩形的权值和超过 ...

  7. 解题:POI 2008 Station

    题面 水水的换根裸题,不过以前还真没做过换根的题 换根的思想就是在DFS中利用树的信息更新出当前点为根时的信息,具体来说一般是考虑子树外和子树内两部分 每个点的答案$ans$就是$ans[fa]+n- ...

  8. [BZOJ 1124][POI 2008] 枪战 Maf

    1124: [POI2008]枪战Maf Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 659  Solved: 259[Submit][Status ...

  9. [POI 2008] BLO

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=1123 [算法] 首先,如果一个点不是割点,那么,去掉该点后不连通的有序点对就为 : ...

随机推荐

  1. 整理下PC和移动获取点击、移动坐标的代码和坑

    一.PC PC是通过鼠标点击和移动,相对比较简单,比如onmousedown.onmouseup.onmousemove.onmouseout鼠标按键按下.按键起来.鼠标在元素上移动.鼠标从元素上离开 ...

  2. I.MX6 dts 在哪里、怎么编译

    /************************************************************************ * I.MX6 DTS 在哪里.怎么编译 * 说明: ...

  3. UVA - 11925 Generating Permutations (思维,构造)

    给你一个长度为n(n<=300)的排列,有两种操作,第一种是交换前两个数,第二种是把第一个数放到最后,让你用不超过2n^2次的操作把一个初始为1-n升序的排列变为该排列. 一开始被紫薯蛋疼的翻译 ...

  4. python爬虫框架Pyspider初次接触

    pyspider网站地址:http://docs.pyspider.org/en/latest/.文档比较好,安装起来也非常方便.既然是基于python的框架,那么首先得安装python.微软出的一款 ...

  5. mysql函数之二:left,right,substring,substring_index MySQL截取字符串函数方法

    函数: 1.从左开始截取字符串 left(str, length) 说明:left(被截取字段,截取长度) 例:select left(content,200) as abstract from my ...

  6. mongo shell命令

    https://docs.mongodb.com/manual/mongo/ 一.MongoDB客户端使用 1.mongo:启动mongo的客户端,和mongo客户端的登录 [root@cmos1 b ...

  7. 【转】ruby中nil?, empty? and blank?的选择

    In Ruby, you check with nil? if an object is nil:article = nil article.nil? # => true empty? chec ...

  8. [Chapter 3 Process]Practice 3.2 Including the initial parent process, how many processes are created by the program shown in Figure?

    3.2 Including the initial parent process, how many processes are created by the program shown in Fig ...

  9. 2014.10.1 Cmd更改系统时间

    Process p = new Process(); //Process类有一个StartInfo属性 //设定程序名 p.StartInfo.FileName = "cmd.exe&quo ...

  10. 如何使用安装光盘为本机创建yum repository

    在CentOS 6上可以使用系统安装光盘为本机创建yum repository,创建过程如下. 创建光盘mount点 [root@centos62 ~]# mkdir /media/CentOS mo ...