洛谷—— P3469 [POI2008]BLO-Blockade

题目描述

There are exactly  towns in Byteotia.

Some towns are connected by bidirectional roads.

There are no crossroads outside towns, though there may be bridges, tunnels and flyovers. Each pair of towns may be connected by at most one direct road. One can get from any town to any other-directly or indirectly.

Each town has exactly one citizen.

For that reason the citizens suffer from loneliness.

It turns out that each citizen would like to pay a visit to    every other citizen (in his host's hometown), and do it    exactly once. So exactly ![](

That's right, should.

Unfortunately, a general strike of programmers, who demand an emergency purchase of software, is under way.

As an act of protest, the programmers plan to block one town of Byteotia, preventing entering it, leaving it, and even passing through.

As we speak, they are debating which town to choose so that the consequences are most severe.

Task Write a programme that:

reads the Byteotian road system's description from the standard input, for each town determines, how many visits could take place if this town were not blocked by programmers, writes out the outcome to the standard output.

给定一张无向图,求每个点被封锁之后有多少个有序点对(x,y)(x!=y,1<=x,y<=n)满足x无法到达y

输入输出格式

输入格式:

In the first line of the standard input there are two positive integers:  and  () denoting the number of towns and roads, respectively.

The towns are numbered from 1 to .

The following  lines contain descriptions of the roads.

Each line contains two integers  and  () and denotes a direct road between towns numbered  and .

输出格式:

Your programme should write out exactly  integers to the standard output, one number per line. The  line should contain the number of visits that could not take place if the programmers blocked the town no. .

输入输出样例

输入样例#1:

5 5
1 2
2 3
1 3
3 4
4 5
输出样例#1:

8
8
16
14
8

思路:

我们来看一下这道题。

思考一下我们要怎样做呢??

看到题目:给定一张无向图,求每个点被封锁之后有多少个有序点对(x,y)(x!=y,1<=x,y<=n)满足x无法到达y以后大佬们就应该猜到了这道题的大致做法:图论。

我们看到样例以后肯定事先不管他三七二十一,先连起边来再说。。

但是连完边以后呢??

有位大佬说:我们连起边以后先把与这个点直接相连的边删掉,然后再判断有几块联通快,又因为每一块联通快内的所有点又都是联通的,所以每一块联通块所不能到达的就是与他不连通的每一块的点数,累加就好了,但由于数据太大,我们就要用树形dp来优化。。。。

但蒟蒻表示并不会树形dp啊。。。。

哎,无奈只能考虑别的做法了。。。。

我们先来看对于被割掉的这个点来说他所不能到达的点恰好是整张图上所有的点(除她自己之外(废话,他肯定能自己到达自己了!!))这样他所不能联通的共有:从他出去到所有的点,从所有的点出去到他,也就是说共有:(n-1)*2对。

再就是对于其他的联通快,我们只需要预处理出每一个点出发到达的点然后再*2就好了。。

又有人要问了:怎样预处理???!!

我们来样例来看一下;;

对于割掉点3来说:不能到达的点是这样来的呢??

割掉点三之后:我们把整张图分成了这样三部分:(1,2),(3),(4,5)。

点1不能到达的点就是(1,3)(1,4)(1,5);

点2不能到达的点为(2,3),(2,4,)(2,5)

点3不能到达的点为((3,1),(3,2),(3,4,),(3,5)

点4.。。。。。。。((4,1)(4,2)(4,3)

点5.。。。。。。。(5,1)(5,2)(5,3)

由于我们要*2嘛,所以这个地方我们只能出已成一对的形式

这样就还剩下(1,3)(1,4)(1,5)(2,3)(2,4)(2,5)(3,4)(3,5)

看看这些,你能发现什么?!

是不是这样对于这个图来说好理解一些

(反掌我是没太理解。。。)

但是这里我们可以用别的来做:我们对于一个点出去他所到达的和能到达它的之外。剩下的就是他相连的联通块之间的相连的了。

我们在来处理这一部分。在tarjan里面,我们处理出这个点所能到达且是他的子树的的联通块的大小,这样他的父亲树的大小就为总点数减去这个点减去他的子树的大小,即n-1-size[i] i为当前点。 这样我们又能得知他们之间不能相连的点数就是他的父亲节点内的个数*塔子树节点内的个数、。即ans【i】=t*(n-t-1) t=size[i] 这样我们求出了从该点外不能互相到达的对数

再加上它能到达的点的对数就是了。不过这里我们处理出来的是单向到达,我们在输出时再乘以二就好了!!

代码:

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define N 100005
#define ll long long
using namespace std;
int n,m,x,y,tot,tim;
int dfn[N],low[N],size[N],head[N],cut_point[N];
ll ans[N];
int read()
{
    ,f=; char ch=getchar();
    ; ch=getchar();}
    +ch-';ch=getchar();}
    return x*f;
}
struct Edge
{
    int from,next,to;
}edge[];
void add(int x,int y)
{
    tot++;
    edge[tot].to=y;
    edge[tot].next=head[x];
    head[x]=tot;
}
int tarjan(int now)
{
    ;size[now]=;
    dfn[now]=low[now]=++tim;
    for(int i=head[now];i;i=edge[i].next)
    {
        int t=edge[i].to;
        if(!dfn[t])
        {
            tarjan(t);
            size[now]+=size[t];
            low[now]=min(low[now],low[t]);
            if(dfn[now]<=low[t])
            {
                ans[now]+=(ll)z*size[t];
                z+=size[t];
            }
        }
        else low[now]=min(low[now],dfn[t]);
    }
    ans[now]+=(ll)z*(n-z-);
}
int main()
{
    n=read();m=read();
    ;i<=m;i++)
     x=read(),y=read(),add(x,y),add(y,x);
    tarjan();
    ;i<=n;i++)
      printf()<<);
    ;
}

3469 [POI2008]BLO-Blockade的更多相关文章

  1. 割点判断+luogu 3469 POI2008 BLO

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

  2. BZOJ 1123: [POI2008]BLO

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

  3. BZOJ1123: [POI2008]BLO

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

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

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

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

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

  6. [POI2008]BLO(Tarjan)

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

  7. 【dfs+连通分量】Bzoj1123 POI2008 BLO

    Description Byteotia城市有n个 towns m条双向roads. 每条 road 连接 两个不同的 towns ,没有重复的road. 所有towns连通. Input 输入n&l ...

  8. BZOJ1123或洛谷3469 [POI2008]BLO-Blockade

    BZOJ原题链接 洛谷原题链接 若第\(i\)个点不是割点,那么只有这个点单独形成一个连通块,其它点依旧连通,则答案为\(2\times (n-1)\). 若第\(i\)个点是割点,那么去掉这个点相关 ...

  9. [POI2008] BLO

    link 试题分析 分两种情况考虑. 当此点不是割点是,答案是$2\times (n-1)$. 当是割点时,我们发现这个点把树分成了若干个联通块,只要两两相乘即可. #include<iostr ...

随机推荐

  1. IP地址 子网掩码 默认网关和DNS服务器的关系

    在过去,男人是需要能够上房揭瓦的,是要能够修水管的.现在的男人是需要会装系统的,会设置路由器的.世界变化太快! 废话不多说,本文来讨论一下电脑上最为常见的几个网络参数:IP地址.子网掩码.默认网关和D ...

  2. 洛谷 P1910 L国的战斗之间谍(水题日常)

    题目背景 L国即将与I国发动战争!! 题目描述 俗话说的好:“知己知彼,百战不殆”.L国的指挥官想派出间谍前往I国,于是,选人工作就落到了你身上. 你现在有N个人选,每个人都有这样一些数据:A(能得到 ...

  3. Mapping (RESOURCE) not found :和BeanFactory not initialized or already closed - call 'refresh' before access记录

    1.Mapping (RESOURCE) not found :cn/sxx/model/Supplier.hbm.xml : origin(cn/sxx/model/Supplier.hbm.xml ...

  4. OpenCV2:第九章 图像比较

    一.简介 图像相似度主要是对两幅图像内容的相似程度进行打分,根据分数的高低来判断图像内容的相似程度. 常见的图像比较有两种方法:峰值信噪比PSNR和结构相似性SSIM 二.峰值信噪比PSNR(Peak ...

  5. lspci详解分析

    lspci详解分析 一.PCI简介 PCI是一种外设总线规范.我们先来看一下什么是总线:总线是一种传输信号的路径或信道.典型情况是,总线是连接于一个或多个导体的电气连线,总 线上连接的所有设备可在同一 ...

  6. Navicat将表转为模型

    右键数据库 -> 逆向数据库到模型

  7. Java中Synchronized和Lock的使用

    Lock的锁定是通过代码实现的,而 synchronized 是在 JVM 层面上实现的 synchronized在锁定时如果方法块抛出异常,JVM 会自动将锁释放掉,不会因为出了异常没有释放锁造成线 ...

  8. Tunnelier使用说明

    Tunnelier与MyEnTunnel类似,但是功能更加强大.MyEnTunnel小巧易用,如何使用MyEnTunnel可以参考 MyEnTunnel使用说明 这里列下Tunnelier的优点: 1 ...

  9. 洛谷 P1518 两只塔姆沃斯牛

    P1518 两只塔姆沃斯牛 The Tamworth Two 简单的模拟题,代码量不大. 他们走的路线取决于障碍物,可以把边界也看成障碍物,遇到就转,枚举次,因为100 * 100 * 4,只有4个可 ...

  10. 洛谷P1421 小玉买文具

    这道题其实就是编程最基础的逻辑,没什么好讲的输入,输出就完了,非常简单! code: #include<cstdio> #include<iostream> using nam ...