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] ...
随机推荐
- JS高级——instanceof语法
基本语法 对象 instanceof 构造函数 基本使用 <script> function Person() { } //p--->Person.prototype--->O ...
- JS——client
clientTop.clientLeft: clientTop:盒子的上boder clientLeft:盒子的左border clientWidth与clientHeight 1.在有DTD情况下: ...
- CSS——个人资料demo
1.上下外边距合并,选最大值. 2.两个input标签在编辑中如果换行了,在浏览器中显示的时候会自动增加一些距离. <!DOCTYPE html> <html lang=" ...
- 【译】x86程序员手册19-6.3.2数据访问的约束
6.3.2 Restricting Access to Data 数据访问的约束 To address operands in memory, an 80386 program must load ...
- 如何在eclipse中设置断点并调试程序
eclipse导入源码后可以看见代码但并不能调试,(解决方法) 1.eclipse默认的运行环境不是jdk中的jre.将jre换成jdk: 2. 先去掉勾,apply,在打上勾,apply 参考:ht ...
- ES6 作用域的问题
- Android组件化最佳实践 ARetrofit原理
ARetrofit原理讲原理之前,我想先说说为什么要ARetrofit.开发ARetrofit这个项目的思路来源其实是Retrofit,Retrofit是Square公司开发的一款针对Android网 ...
- SweetAlert弹出框
以前也用过,那个时候没有写过,突然看见了,就写上了. 网址:http://mishengqiang.com/sweetalert2/ swal({ title: '确定删除吗?', text: '你将 ...
- cogs——66. [HAOI2004模拟] 数列问题
66. [HAOI2004模拟] 数列问题 本以为会TLE,可... dfs水题(很基础) #include<bits/stdc++.h> using namespace std; ],a ...
- JS练习:定时弹出广告
代码: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title ...