bzoj1123 [POI2008]BLO——求割点子树相乘
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1123
思路倒是有的,不就是个乘法原理吗,可是不会写...代码能力...
写了一堆麻麻烦烦乱七八糟的东西写不下去了,去看TJ...
原来是在 tarjan 里面就顺便算出来了啊!真是精妙!这就是构建出了一个 dfs 搜索树了呢;
码力还需多多提升...
代码如下:
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
int const maxn=1e5+,maxm=5e5+;
int n,m,hd[maxn],ct,siz[maxn],dfn[maxn],low[maxn],tim;
ll ans[maxn];
struct N{
int to,nxt;
N(int t=,int n=):to(t),nxt(n) {}
}ed[maxm<<],edge[maxm<<];
void add(int x,int y){ed[++ct]=N(y,hd[x]); hd[x]=ct;}
void tarjan(int x,int f)
{
dfn[x]=low[x]=++tim;
ll t=; siz[x]=;//注意t是ll,否则下面算给ans时爆int
for(int i=hd[x],u;i;i=ed[i].nxt)
{
if((u=ed[i].to)==f)continue;
if(!dfn[u])
{
tarjan(u,x); siz[x]+=siz[u];
low[x]=min(low[x],low[u]);
if(low[u]>=dfn[x])ans[x]+=siz[u]*t,t+=siz[u];//t是割点的子树大小
}
else low[x]=min(low[x],dfn[u]);
}
ans[x]+=t*(n-t-);
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=,x,y;i<=m;i++)
{
scanf("%d%d",&x,&y);
add(x,y); add(y,x);
}
tarjan(,);
for(int i=;i<=n;i++)printf("%lld\n",(ans[i]+n-)*);
return ;
}
bzoj1123 [POI2008]BLO——求割点子树相乘的更多相关文章
- BZOJ 1123: [POI2008]BLO 求割点_乘法原理_计数
Description Byteotia城市有n个 towns m条双向roads. 每条 road 连接 两个不同的 towns ,没有重复的road. 所有towns连通. Input 输入n&l ...
- BZOJ1123: [POI2008]BLO
1123: [POI2008]BLO Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 614 Solved: 235[Submit][Status] ...
- BZOJ1123 [POI2008]BLO(割点判断 + 点双联通缩点size)
#include <iostream> #include <cstring> #include <cstdio> using namespace std; type ...
- 【dfs+连通分量】Bzoj1123 POI2008 BLO
Description Byteotia城市有n个 towns m条双向roads. 每条 road 连接 两个不同的 towns ,没有重复的road. 所有towns连通. Input 输入n&l ...
- BZOJ1123:[POI2008]BLO(双连通分量)
Description Byteotia城市有n个 towns m条双向roads. 每条 road 连接 两个不同的 towns ,没有重复的road. 所有towns连通. Input 输入n&l ...
- [BZOJ1123]:[POI2008]BLO(塔尖)
题目传送门 题目描述 Byteotia城市有n个towns.m条双向roads.每条road连接两个不同的towns,没有重复的road.所有towns连通. 输入格式 输入n,m及m条边. 输出格式 ...
- bzoj 1123 [POI2008]BLO Tarjan求割点
[POI2008]BLO Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1540 Solved: 711[Submit][Status][Discu ...
- [POI2008]BLO(Tarjan)
[POI2008]BLO Description Byteotia城市有\(n\)个 towns \(m\)条双向roads. 每条 road 连接 两个不同的 towns ,没有重复的road. 所 ...
- BZOJ 1123: [POI2008]BLO
1123: [POI2008]BLO Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1030 Solved: 440[Submit][Status] ...
随机推荐
- day04-交互、格式化输出及基本运算符
目录 与用户交互 python2和python3交互的区别 格式化输出 1 字符串拼接 2 占位符 3 format格式 4 f-string格式 基本运算符 算术运算符 比较运算符 赋值运算符 逻辑 ...
- * 获取页面参数 * @return 参数打印
/** * 获取页面参数 * @return 参数打印 */ GetUrlParam: function(paraName) { var url = document.location.toStrin ...
- Render2
https://blog.csdn.net/wf19930209/article/details/81109388
- Asp.Mvc 常用
url转义 var address = "http://www.cnblog.com"; var a22 = Uri.EscapeDataString(address); var ...
- 名字竞技场 V3.0
更新内容 1.加入新boss,更高的难度. 2.支持组队模式勒! 3.针对大家反应的人物属性算法进行了修改,现在人物属性更多的取决于名字而不是随机数 4.用户界面优化 INF.代码拿走赞留下,不然你赢 ...
- js调用ro的webservice
Enabling JavaScript Access on the Server Drop the JavaScriptHttpDispatcher component onto the server ...
- hadoop-磁盘出现坏盘,如何能在线换盘
涉及到磁盘存储路径的配置文件参数有: hdfs-site.xml <name>dfs.datanode.data.dir</name> yarn-site.xml <na ...
- Spring MVC-视图解析器(View Resolverr)-XML视图解析器(Xml View Resolver)示例(转载实践)
以下内容翻译自:https://www.tutorialspoint.com/springmvc/springmvc_xmlviewresolver.htm 说明:示例基于Spring MVC 4.1 ...
- mongodb之配置
前言 最新版本支持yaml格式的配置文件,只支持空格,不能使用tab 详细配置说明 #系统日志配置 systemLog: destination: file path: /var/log/mongod ...
- POJ 3748:位操作
位操作 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8964 Accepted: 3581 Description 如 ...