*题目描述:
Byteotia城市有n个 towns m条双向roads. 每条 road 连接 两个不同的 towns ,没有重复的road. 所有towns连通。
*输入
输入n<=100000 m<=500000及m条边
*输出:
输出n个数,代表如果把第i个点去掉,将有多少对点不能互通。
*样例输入:
5 5
1 2
2 3
1 3
3 4
4 5
*样例输出:
8
8
16
14
8
*题解:
裸的找割点。答案就是每个割点的子树的大小乘上除了子树外的点,还有子树和子树之间的对数,最后还有每个点和其他n-1个点的对数。
*代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath> #ifdef WIN32
#define LL "%I64d"
#else
#define LL "%lld"
#endif #ifdef CT
#define debug(...) printf(__VA_ARGS__)
#define setfile()
#else
#define debug(...)
#define filename ""
#define setfile() freopen(filename".in", "r", stdin); freopen(filename".out", "w", stdout);
#endif #define R register
#define getc() (S == T && (T = (S = B) + fread(B, 1, 1 << 15, stdin), S == T) ? EOF : *S++)
#define dmax(_a, _b) ((_a) > (_b) ? (_a) : (_b))
#define dmin(_a, _b) ((_a) < (_b) ? (_a) : (_b))
#define cmax(_a, _b) (_a < (_b) ? _a = (_b) : 0)
#define cmin(_a, _b) (_a > (_b) ? _a = (_b) : 0)
char B[1 << 15], *S = B, *T = B;
inline int FastIn()
{
R char ch; R int cnt = 0; R bool minus = 0;
while (ch = getc(), (ch < '0' || ch > '9') && ch != '-') ;
ch == '-' ? minus = 1 : cnt = ch - '0';
while (ch = getc(), ch >= '0' && ch <= '9') cnt = cnt * 10 + ch - '0';
return minus ? -cnt : cnt;
}
#define maxn 100010
#define maxm 1000010
struct Edge
{
Edge *next;
int to;
}*last[maxn], e[maxm], *ecnt = e;
inline void link(R int a, R int b)
{
*++ecnt = (Edge) {last[a], b}; last[a] = ecnt;
}
int dfn[maxn], low[maxn], timer, n, m, size[maxn];
long long ans[maxn];
void dfs(R int x, R int fa)
{
dfn[x] = low[x] = ++timer;
size[x] = 1;
R int tmp = 0;
for (R Edge *iter = last[x]; iter; iter = iter -> next)
{
R int pre = iter -> to;
if (pre != fa)
{
if (!dfn[pre])
{
dfs(pre, x);
size[x] += size[pre];
cmin(low[x], low[pre]);
if (dfn[x] <= low[pre])
{
ans[x] += 1ll * tmp * size[pre];
tmp += size[pre];
}
}
else cmin(low[x], dfn[pre]);
}
}
ans[x] += 1ll * tmp * (n - 1 - tmp);
}
int main()
{
// setfile();
n = FastIn(), m = FastIn();
for (R int i = 1; i <= m; ++i)
{
R int a = FastIn(), b = FastIn();
link(a, b); link(b, a);
}
dfs(1, 0);
for (R int i= 1; i <= n; ++i) printf("%lld\n", (ans[i] + n - 1) << 1 );
return 0;
}

【bzoj1123】[POI2008]BLO的更多相关文章

  1. 【bzoj1123】[POI2008]BLO DFS树

    题目描述 Byteotia城市有n个 towns m条双向roads. 每条 road 连接 两个不同的 towns ,没有重复的road. 所有towns连通. 输入 输入n<=100000 ...

  2. 【BZOJ1123】 [POI2008]BLO (tarjan)

    tarjan判断割点...拿掉一个点之后,会被分成若干个联通块,用节点个数和统计一下他们相互不能到达的个数就好. ; maxm=; type edgetype=record toward,next:l ...

  3. 【BZOJ1112】[POI2008]砖块Klo Treap

    [BZOJ1112][POI2008]砖块Klo Description N柱砖,希望有连续K柱的高度是一样的. 你可以选择以下两个动作 1:从某柱砖的顶端拿一块砖出来,丢掉不要了. 2:从仓库中拿出 ...

  4. 【BZOJ1116】[POI2008]CLO 并查集

    [BZOJ1116][POI2008]CLO Description Byteotia城市有n个 towns m条双向roads. 每条 road 连接 两个不同的 towns ,没有重复的road. ...

  5. 【BZOJ1132】[POI2008]Tro 几何

    [BZOJ1132][POI2008]Tro Description 平面上有N个点. 求出所有以这N个点为顶点的三角形的面积和 N<=3000 Input 第一行给出数字N,N在[3,3000 ...

  6. 【BZOJ1125】[POI2008]Poc hash+map+SBT

    [BZOJ1125][POI2008]Poc Description n列火车,每条有l节车厢.每节车厢有一种颜色(用小写字母表示).有m次车厢交换操作.求:对于每列火车,在交换车厢的某个时刻,与其颜 ...

  7. 【BZOJ1124】[POI2008]枪战Maf 贪心+思路题

    [BZOJ1124][POI2008]枪战Maf Description 有n个人,每个人手里有一把手枪.一开始所有人都选定一个人瞄准(有可能瞄准自己).然后他们按某个顺序开枪,且任意时刻只有一个人开 ...

  8. 【BZOJ-1123】BLO Tarjan 点双连通分量

    1123: [POI2008]BLO Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 970  Solved: 408[Submit][Status][ ...

  9. 【bzoj1123】BLO

    1123: [POI2008]BLO Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2222  Solved: 1090[Submit][Status ...

随机推荐

  1. 11.metasploit辅助模块----基本Exp----ARP欺骗中间人MITM----WordPress破解

    metasploit辅助模块 信息收集 auxiliary scanners 使用metasploitable靶机 桥接 同一局域网 msfconsole nmap -sT 靶机IP nmap -sS ...

  2. 9.shodan搜索引擎----Metasploit Web GUI----取证工具箱----sAINT间谍软件

    shodan搜索引擎 物联网搜索引擎 访问路由器,服务器,网络摄像头,安装CLI banner抓取,端口扫描 www.shodan.io 需要注册账户,支持google账户 搜索 webcams 网络 ...

  3. itchat监听微信撤回消息

    import itchat from itchat.content import * import re msg_infomation = {} # 监听发送消息 @itchat.msg_regist ...

  4. Flask框架(五) —— session源码分析

    Flask框架(五) —— session源码分析 目录 session源码分析 1.请求来了,执行__call__方法 2.__call__方法 3.调用__call__方法 3.1.ctx = s ...

  5. nodejs 对接微信 express 对接微信

    安装引用 npm install express npm install body-parser npm install express-xml-bodyparser npm install axio ...

  6. 函数 FUNCTION

    函数 FUNCTION 定义: 带名字的代码块,用于执行具体任务. 注意: 应给函数指定描述性名称,只是用小写字母和下划线. 函数代码块以 def 关键词开头,后接函数标识符名称和圆括号 (). 任何 ...

  7. 循环结构 :for

    循环结构 :for 循环四要素: 1.初始化条件 2.循环条件 3.循环体 4.迭代条件 格式: for(初始化条件;循环条件;迭代条件){ 循环体; } 执行顺序 :1 -> 2 -> ...

  8. 17: VUE数据绑定 与 Object.defineProperty

    VUE数据绑定原理:https://segmentfault.com/a/1190000006599500?utm_source=tag-newest Object.defineProperty(): ...

  9. PY个树状数组

    树状数组看起来比较简单,于是就挑它下手了... 于是生活终于也对咱下手了... 要讲的就两个东西,一个是开数组,全局变量写最前面,数组是这么开的: f=[0 for i in range(500005 ...

  10. 安装最新版Elasticsearch报错

    1 问题:ERROR: bootstrap checks failed max file descriptors [4096] for elasticsearch process likely too ...