题目链接:https://www.luogu.org/problemnew/show/P3469

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;
const int maxn = 500000 + 10;
ll n, m, ans[maxn];
ll dfn[maxn], low[maxn], tim, size[maxn];
bool iscut[maxn];
struct edge{
ll from, to, next;
}e[maxn<<2];
ll head[maxn], cnt;
void add(ll u, ll v)
{
e[++cnt].from = u;
e[cnt].next = head[u];
e[cnt].to = v;
head[u] = cnt;
}
void tarjan(ll x, ll fa)
{
ll child = 0, sum = 0;
dfn[x] = low[x] = ++tim;
size[x] = 1;
for(ll i = head[x]; i != -1; i = e[i].next)
{
ll v = e[i].to;
if(!dfn[v])
{
tarjan(v,fa);
size[x] += size[v];
low[x] = min(low[x], low[v]);
if(low[v] >= dfn[x])
{
ans[x] += size[v]*(n - size[v]);
sum += size[v];
child++;
if(x != fa)
iscut[x] = 1;
}
if(x == fa) child++;
}
low[x] = min(low[x], dfn[v]);
}
if(x == fa && child >= 2) iscut[fa] = 1;
if(!iscut[x]) ans[x] = 2*(n-1);
else ans[x] += (n-sum-1)*(sum+1)+n-1;
}
int main()
{
memset(head, -1, sizeof(head));
scanf("%lld%lld",&n,&m);
for(ll i = 1; i <= m; i++)
{
ll u, v;
scanf("%lld%lld",&u,&v);
add(u,v),add(v,u);
}
tarjan(1,1);
for(ll i = 1; i <= n; i++)
printf("%lld\n",ans[i]);
return 0;
}

【luogu P3469 [POI2008]BLO-Blockade】 题解的更多相关文章

  1. [Luogu P3469] [POI2008]BLO-Blockade (割点)

    题面 传送门:https://www.luogu.org/problemnew/show/P3469 Solution 先跟我大声念: poi! 然后开始干正事. 首先,我们先把题目中的点分为两类:去 ...

  2. [LUOGU] P3469 [POI2008]BLO-Blockade

    https://www.luogu.org/problemnew/show/P3469 求无向图分别删去每个点后不连通的点对数. 首先,对于任何一个点,它本身删了,就会和剩下的n-1个点不连通,点对是 ...

  3. 割点判断+luogu 3469 POI2008 BLO

    1.根节点,有2棵及以上子树 2.非根节点,有子节点dfn[u]<=low[v] #include <bits/stdc++.h> #define N 1000050 using n ...

  4. BZOJ 1123 && Luogu P3469 [POI2008]BLO-Blockade 割点+乘法原理

    想了半天式子...最后在邓大师的帮助下想出此题....QWQ我还是太菜了 对于一个非割点,ans+=2*(n-1); 对于一个割点,ans+= #include<cstdio> #incl ...

  5. BZOJ1123: [POI2008]BLO

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

  6. bzoj 1123 [POI2008]BLO Tarjan求割点

    [POI2008]BLO Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1540  Solved: 711[Submit][Status][Discu ...

  7. 洛谷 P3469 [POI2008]BLO-Blockade (Tarjan,割点)

    P3469 [POI2008]BLO-Blockade https://www.luogu.org/problem/P3469 题目描述 There are exactly nn towns in B ...

  8. BZOJ 1123: [POI2008]BLO

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

  9. BZOJ 1123: [POI2008]BLO( tarjan )

    tarjan找割点..不是割点答案就是(N-1)*2, 是割点的话就在tarjan的时候顺便统计一下 ------------------------------------------------- ...

随机推荐

  1. flume 自定义sink

    http://flume.apache.org/FlumeDeveloperGuide.html#sink 看了 还是比较好上手的,简单翻译一下 sink的作用是从 Channel 提取 Event  ...

  2. 网络连接和初始HTTP请求

    浏览器检索网页,先从URL开始,使用DNS确定IP地址,再用基于TCP和HTTP协议连接到服务器,请求相关的内容,得到相应,浏览器解析并呈现到屏幕上.服务器响应后,浏览器响应不会同时全部到达,会陆续到 ...

  3. SQL Server Profiler(转载)

    SQL Server Profiler工具 一.SQL Profiler工具简介 SQL Profiler是一个图形界面和一组系统存储过程,其作用如下: 图形化监视SQL Server查询: 在后台收 ...

  4. c# winform 欢迎界面时加载数据

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  5. 模糊查询-动态参数,防SQL注入

    WHERE("title like '%'+#{keyWord}+'%'"); -MS SQL WHERE("title like concat('%',#{keyWor ...

  6. MVC页面简单post提交

    页面代码 <script src="~/Scripts/jquery-1.10.2.js"></script> <script> $(funct ...

  7. (三)PHP网页架站

    目前,Windows下已经有集成的PHP网页架站工具,例如:AppServ.WampServer.这些软件将Apache.PHP.MySQL.phpMyAdmin集成到一起,极大地方便了开发者架站.但 ...

  8. webpack初步搭建Vue项目

    对文件进行打包 1. cnpm i -D webpack webpack-cli 本地热更新 1. cnpm i -D webpack-dev-server 处理图片资源 url-loader依赖fi ...

  9. oracle之数据同步:Oracle Sql Loader使用说明(大批量快速插入数据库记录)

    1.准备表数据 select * from emp10; create sequence seq_eseq increment start maxvalue ; --得到序列的SQL语句 select ...

  10. jq实现发送验证码倒计时60s

    setInterval() :按照指定的周期(以毫秒计)来调用函数或计算表达式.方法会不停地调用函数,直到 clearInterval() 被调用或窗口被关闭. setTimeout() :在指定的毫 ...