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] ...
随机推荐
- ubuntuKylin17.04重装KDE
不小心安装了一个不知道什么的东西,把libROS的那一套都给卸载了,然后删除掉了KDE的很多库.然后KDM也丢失了.KDE界面启动之后,plasma-desktop界面也启动不了.选择重装. 然而出现 ...
- C# 获得Properties下的定义的资源
var str1 = Properties.Resources.ResourceManager.GetObject("String1", null); string url = S ...
- html table内容不随标题滚动
<html><head></head><body> <div> <div id="demo" style=&quo ...
- gitlab 第1次提交代码到1个新仓库
1.如果是本地刚刚搭建好git环境,第一次和gitlab服务器产生连接 参照这个文 https://www.cnblogs.com/kaerxifa/p/10929098.html 2.已经和gitl ...
- IntentService和HandlerThread的使用以及源码阅读
使用MyIntentService.java public class MyIntentService extends IntentService { /** * 是否正在运行 */ private ...
- 比n大的最小不重复数
void Calculate(int a) { int pa = a; ; ] = {}; //将pa按位存储到数组b ) { b[count++] = pa%; pa = pa/; } bool f ...
- 标准C 语言总结
***************C语言****************** --day01-- Linux是一个和Windows类似的操作系统 通常通过终端软件使用Linux操作系统 终端软件里只能使用 ...
- ORM 事务
orm 事务: import datetime from appxx import models try: from django.db import transaction with transac ...
- MySQL-----一对多
一对多: 用户表和部门表 用户: 用户id 用户名 部门 1 George 1 2 Elizabeth 1 3 Bruce 2 4 Catherine 3 部门: 部门id 部门名称 1 CEO ...
- 利用Linux中的crontab实现分布式项目定时任务
@Controller @RequestMapping("/task/topic") public class TopicQuartzController { protected ...