1123: [POI2008]BLO

Time Limit: 10 Sec  Memory Limit: 162 MB
Submit: 970  Solved: 408
[Submit][Status][Discuss]

Description

Byteotia城市有n个 towns m条双向roads. 每条 road 连接 两个不同的 towns ,没有重复的road. 所有towns连通。

Input

输入n<=100000 m<=500000及m条边

Output

输出n个数,代表如果把第i个点去掉,将有多少对点不能互通。

Sample Input

5 5
1 2
2 3
1 3
3 4
4 5

Sample Output

8
8
16
14
8

HINT

Source

Solution

题意叙述不清。

题目大意:给定N个点M条边的无向图,问删除每个点后,对于有序数对(x,y)满足x,y互不连通的数对数。其中,被删掉的点也应被统计。

这种和删点,联通有关的,可以考虑割点/点双联通分量。

这个题也是,如果删除一个割点,那么答案个数就是裂成的几个块用乘法原理统计答案。如果删除一个非割点则可能会对其他点直接不影响。

可以考虑在Tarjan的过程中求解,我们额外记录一个size表示分成的联通块的大小,然后我们在Tarjan的过程中统计答案即可

Code

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
#define LL long long
inline int read()
{
int x=,f=; char ch=getchar();
while (ch<'' || ch>'') {if (ch=='-') f=-; ch=getchar();}
while (ch>='' && ch<='') {x=x*+ch-''; ch=getchar();}
return x*f;
}
#define MAXN 100010
#define MAXM 500010
struct EdgeNode{int next,to;}edge[MAXM<<];
int head[MAXN],cnt=;
inline void AddEdge(int u,int v) {cnt++; edge[cnt].next=head[u]; head[u]=cnt; edge[cnt].to=v;}
inline void InsertEdge(int u,int v) {AddEdge(u,v); AddEdge(v,u);}
int N,M;
vector<int>BCC[MAXN];
#define Pa pair<int,int>
Pa st[MAXM]; int top;
int dfn[MAXN],low[MAXN],dfsn,son[MAXN],size[MAXN],cut[MAXN],bcc,belong[MAXN];
LL sum[MAXN];
inline void Tarjan(int now,int last)
{
dfn[now]=low[now]=++dfsn; LL su=; size[now]=;
for (int i=head[now]; i; i=edge[i].next)
if (!dfn[edge[i].to])
{
st[++top]=make_pair(now,edge[i].to); son[now]++;
Tarjan(edge[i].to,now); low[now]=min(low[now],low[edge[i].to]);
size[now]+=size[edge[i].to];
if (dfn[now]<=low[edge[i].to])
{
sum[now]+=su*size[edge[i].to]; su+=(LL)size[edge[i].to];
cut[now]=; bcc++; BCC[bcc].clear(); int tnow=-,tto=-;
while (tnow!=now && tto!=edge[i].to)
{
tnow=st[top].first,tto=st[top].second; top--;
if (belong[tnow]!=bcc) BCC[bcc].push_back(tnow),belong[tnow]=bcc;
if (belong[tto]!=bcc) BCC[bcc].push_back(tto),belong[tto]=bcc;
}
}
}
else if (dfn[edge[i].to]<dfn[now] && edge[i].to!=last)
st[++top]=make_pair(now,edge[i].to),low[now]=min(low[now],dfn[edge[i].to]);
if (last< && son[now]==) cut[now]=;
sum[now]+=su*(N-su-);
}
int main()
{
N=read(),M=read();
for (int x,y,i=; i<=M; i++) x=read(),y=read(),InsertEdge(x,y);
for (int i=; i<=N; i++) if (!dfn[i]) Tarjan(i,-);
for (int i=; i<=N; i++) printf("%lld\n",(LL)(sum[i]+N-)*);
return ;
}

【BZOJ-1123】BLO Tarjan 点双连通分量的更多相关文章

  1. 【Codefoces487E/UOJ#30】Tourists Tarjan 点双连通分量 + 树链剖分

    E. Tourists time limit per test: 2 seconds memory limit per test: 256 megabytes input: standard inpu ...

  2. [LA3523/uva10195]圆桌骑士 tarjan点双连通分量+奇环定理+二分图判定

    1.一个环上的各点必定在同一个点双连通分量内: 2.如果一个点双连通分量是二分图,就不可能有奇环: 最基本的二分图中的一个环: #include<cstdio> #include<c ...

  3. POJ 3177 Redundant Paths (tarjan边双连通分量)

    题目连接:http://poj.org/problem?id=3177 题目大意是给定一些牧场,牧场和牧场之间可能存在道路相连,要求从一个牧场到另一个牧场要有至少两条以上不同的路径,且路径的每条pat ...

  4. codeforces 962F.simple cycle(tarjan/点双连通分量)

    题目连接:http://codeforces.com/contest/962/problem/F 题目大意是定义一个simple cycle为从一个节点开始绕环走一遍能经过simple cycle内任 ...

  5. 图连通性【tarjan点双连通分量、边双联通分量】【无向图】

    根据 李煜东大牛:图连通性若干拓展问题探讨 ppt学习. 有割点不一定有割边,有割边不一定有割点. 理解low[u]的定义很重要. 1.无向图求割点.点双联通分量: 如果对一条边(x,y),如果low ...

  6. tarjan 边双连通分量 对点进行分组 每组点都在一个双连通分量里边

    int dfn[N],low[N],id[N],s[N],p,num,t,son[N];//dfn记录dfs时间戳//low代表当前点到达的最小时间戳,id对点进行分组编号.num是时间戳//s临时存 ...

  7. BZOJ 1123 BLO

    tarjan求割点计算答案.注意不是每一棵子树都算答案.开个变量记一下. #include<iostream> #include<cstdio> #include<cst ...

  8. bzoj 1123 [POI2008]BLO——点双连通分量

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1123 点双连通分量缩点,然后各种各样. 结果不会写了.比如新连边.记录一个点是割点缩成的点还 ...

  9. tarjan算法与无向图的连通性(割点,桥,双连通分量,缩点)

    基本概念 给定无向连通图G = (V, E)割点:对于x∈V,从图中删去节点x以及所有与x关联的边之后,G分裂为两个或两个以上不相连的子图,则称x为割点割边(桥)若对于e∈E,从图中删去边e之后,G分 ...

随机推荐

  1. iOS 9.3真机适配-Could not find Developer Disk Image问题

    Could not find Developer Disk Image 这是由于真机系统过高或者过低,Xcode中没有匹配的配置包文件,我们可以通过这个路径进入配置包的存放目录: /Applicati ...

  2. ToolBar和DrawerLayout的使用实现侧拉栏抽屉的开闭

    1.如图可以看到textColorPrimary,colorPrimary,colorPrimaryDark,navigationBarColor等颜色属性代表的相应位置,如下图 2.具体属性在res ...

  3. dropzonejs中文翻译手册 DropzoneJS是一个提供文件拖拽上传并且提供图片预览的开源类库.

    http://wxb.github.io/dropzonejs.com.zh-CN/dropzonezh-CN/ 由于项目需要,完成一个web的图片拖拽上传,也就顺便学习和了解了一下前端的比较新的技术 ...

  4. 从零自学Hadoop(12):Hadoop命令中

    阅读目录 序 HDFS Commands User Commands Administration Commands Debug Commands 引用 系列索引 本文版权归mephisto和博客园共 ...

  5. 在虚拟机中安装红旗桌面7.0 Linux操作系统的详细图文教程

    本文作者:souvc 本文出处:http://www.cnblogs.com/liuhongfeng/p/5343087.html 以下是详细的内容: 一.安装虚拟机. 安装虚拟机可以参考:在Wind ...

  6. Python进阶【第二篇】多线程、消息队列queue

    1.Python多线程.多进程 目的提高并发 1.一个应用程序,可以有多进程和多线程 2.默认:单进程,单线程 3.单进程,多线程 IO操作,不占用CPU python的多线程:IO操作,多线程提供并 ...

  7. 2-2 Linux 根文件系统详解

    根据马哥Linux初级视频2-3 1. 根文件下的一级目录 #ls / 1. / boot 系统启动相关的文件.如内核.initrd   (initialization run directory) ...

  8. shell 判断语句

    1.字符串判断 str1 = str2 当两个串有相同内容.长度时为真str1 != str2 当串str1和str2不等时为真-n str1 当串的长度大于0时为真(串非空)-z str1 当串的长 ...

  9. Maven 的classifier的作用

    直接看一个例子,maven中要引入json包,于是使用了 <dependency> <groupId>net.sf.json-lib</groupId> <a ...

  10. linux tomcat 的安装

    1.tomcat6 下载地址 http://tomcat.apache.org/download-60.cgi 下载的话,下载那个.tar.gz后缀名的即可. 好像在 Linux.Unix上tomca ...