【洛谷】3469:[POI2008]BLO-Blockade【割点统计size】
P3469 [POI2008]BLO-Blockade
题意翻译
在Byteotia有n个城镇。 一些城镇之间由无向边连接。 在城镇外没有十字路口,尽管可能有桥,隧道或者高架公路(反正不考虑这些)。每两个城镇之间至多只有一条直接连接的道路。人们可以从任意一个城镇直接或间接到达另一个城镇。 每个城镇都有一个公民,他们被孤独所困扰。事实证明,每个公民都想拜访其他所有公民一次(在主人所在的城镇)。所以,一共会有n*(n-1)次拜访。
不幸的是,一个程序员总罢工正在进行中,那些程序员迫切要求购买某个软件。
作为抗议行动,程序员们计划封锁一些城镇,阻止人们进入,离开或者路过那里。
正如我们所说,他们正在讨论选择哪些城镇会导致最严重的后果。
编写一个程序:
读入Byteotia的道路系统,对于每个被决定的城镇,如果它被封锁,有多少访问不会发生,输出结果。
输入输出格式
第一行读入n,m,分别是城镇数目和道路数目
城镇编号1~n
接下来m行每行两个数字a,b,表示a和b之间有有一条无向边
输出n行,每行一个数字,为第i个城镇被锁时不能发生的访问的数量。
@[chen_zhe](/space/show?uid=8457)
翻译提供者:Park
题目描述
There are exactly nn 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 n\cdot (n-1)n⋅(n−1) visits should take place.
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: nn and mm (1\le n\le 100\ 0001≤n≤100 000, 1\le m\le 500\ 0001≤m≤500 000) denoting the number of towns and roads, respectively.
The towns are numbered from 1 to nn.
The following mm lines contain descriptions of the roads.
Each line contains two integers aa and bb (1\le a<b\le n1≤a<b≤n) and denotes a direct road between towns numbered aaand bb.
输出格式:
Your programme should write out exactly nn integers to the standard output, one number per line. The i^{th}ith line should contain the number of visits that could not take place if the programmers blocked the town no. ii.
输入输出样例
Solution
不是割点的点所产生的贡献肯定是$2*(n-1)$,如果是割点,那么就是像统计子树一样要统计出这个点能到达的点和能到达它的点的数量,进行乘法原理计算方案数。
在$tarjan$的过程中可以像走树一样,把能到达的点当成子树统计size,每次加上这个子树的size乘上之前走过的子树的size即可,最后再把内外的点对数的贡献加上即可。
Code
#include<bits/stdc++.h>
#define LL long long
using namespace std; int n, m; struct Node {
int u, v, nex;
Node(){ }
Node(int u, int v, int nex) :
u(u), v(v), nex(nex) { }
} Edge[]; int h[], stot = ;
void add(int u, int v) {
Edge[++stot] = Node(u, v, h[u]);
h[u] = stot;
} LL ans[];
int dfn[], low[], idc, siz[];
void tarjan(int u) {
dfn[u] = low[u] = ++ idc;
int tot = ;
siz[u] = ;
for(int i = h[u]; i; i = Edge[i].nex) {
int v = Edge[i].v;
if(!dfn[v]) {
tarjan(v);
siz[u] += siz[v];
low[u] = min(low[u], low[v]);
if(low[v] >= dfn[u]) {
ans[u] += 1ll * tot * siz[v];
tot += siz[v];
}
} else low[u] = min(low[u], dfn[v]);
}
ans[u] += 1ll * tot * (n - tot - );
} int main() {
scanf("%d%d", &n, &m);
for(int i = ; i <= m; i ++) {
int u, v;
scanf("%d%d", &u, &v);
add(u, v); add(v, u);
}
tarjan();
for(int i = ; i <= n; i ++)
printf("%lld\n", (ans[i] + n - ) << );
return ;
}
【洛谷】3469:[POI2008]BLO-Blockade【割点统计size】的更多相关文章
- BZOJ1123或洛谷3469 [POI2008]BLO-Blockade
BZOJ原题链接 洛谷原题链接 若第\(i\)个点不是割点,那么只有这个点单独形成一个连通块,其它点依旧连通,则答案为\(2\times (n-1)\). 若第\(i\)个点是割点,那么去掉这个点相关 ...
- 「洛谷3469」「POI2008」BLO-Blockade【Tarjan求割点】
题目链接 [洛谷传送门] 题解 很显然,当这个点不是割点的时候,答案是\(2*(n-1)\) 如果这个点是割点,那么答案就是两两被分开的联通分量之间求组合数. 代码 #include <bits ...
- 洛谷3388 【模板】割点 tarjan算法
题目描述 给出一个n个点,m条边的无向图,求图的割点. 关于割点 在无向连通图中,如果将其中一个点以及所有连接该点的边去掉,图就不再连通,那么这个点就叫做割点(cut vertex / articul ...
- 洛谷 P3478 [POI2008]STA-Station
题目描述 The first stage of train system reform (that has been described in the problem Railways of the ...
- 洛谷 P3469 [POI2008]BLO-Blockade (Tarjan,割点)
P3469 [POI2008]BLO-Blockade https://www.luogu.org/problem/P3469 题目描述 There are exactly nn towns in B ...
- 割点判断+luogu 3469 POI2008 BLO
1.根节点,有2棵及以上子树 2.非根节点,有子节点dfn[u]<=low[v] #include <bits/stdc++.h> #define N 1000050 using n ...
- 洛谷P3388 【模板】割点
给出一个n个点,m条边的无向图,求图的割点. u是cut vertex的两个条件: 1.存在v使v及其所有后代没有反向边连回u的祖先 2.u是根且有两个以上子节点 dfs一遍 low[u]是u及其后代 ...
- 洛谷P3469[POI2008]BLO-Blockade
题目 割点模板题. 可以将图中的所有点分成两部分,一部分是去掉之后不影响图的连通性的点,一部分是去掉之后影响连通性的点,称其为割点. 然后分两种情况讨论,如果该点不是割点,则最终结果直接加上2*(n- ...
- 洛谷P3388 【模板】割点(割顶)
题目背景 割点 题目描述 给出一个n个点,m条边的无向图,求图的割点. 输入输出格式 输入格式: 第一行输入n,m 下面m行每行输入x,y表示x到y有一条边 输出格式: 第一行输出割点个数 第二行按照 ...
随机推荐
- vi 编辑器使用技巧
1.由命令"vi --version"所显示的内容知vi的全局配置文件 2.显示行号 ,非编辑模式输入 : set nu 3.显示颜色 1)在文件中找到 "synta ...
- centos7.2系统没有eth0网卡
最近一直在学centos7.5系统,偶然看到虚拟机里有7.2系统所以想练习一下(其实7.2和7.5差不多),但是打开虚拟机之后,发现没有eth0网卡 那没有eth0网卡就无法远程连接ssh,既然遇到了 ...
- [How to] Phoenix 与 CDH5.4.2 HBase的整合
1.简介 Phoenix将SQL带回到了NOSQL的世界,其在HBase之上做了一个layer,客户端通过SQL调用Phoenix,Phoenix在转化为HBase客户算API进行访问HBase,其很 ...
- Flask: Quickstart解读
Windows 10家庭中文版,Python 3.6.4,Flask 1.0.2 从示例代码说起: from flask import Flask app = Flask(__name__) @app ...
- 博客转移至github
博客转移到github 鉴于github的各种优势,博客转移!
- C++ 必须使用初始化列表
继承关系中,父类无默认构造函数 类类型类成员变量无默认构造函数 const类型成员变量 引用类型成员变量 不使用初始化列表,在创建对象调用构造函数之前会对所有的成员变量进行默认初始化,然后再执行构造函 ...
- 安装mysql-python报错解决办法
报错: 按照网上的办法,安装mysql-connector-c-6.1.10-winx64.msi和MySQL-python-1.2.3.win-amd64-py2.7 .exe都不行,又源码安装My ...
- 如何使用django+celery+RabbitMQ实现异步执行
1)安装需要安装RabbitMQ.Celery和Django-celeryCelery和Django-celery的安装直接pip就好 2)修改settings.py在INSTALLED_APPS中加 ...
- C#基础之数据类型
c#有15个预定义类型,其中13个是值类型,两个是引用类型(string 和 object) 1.整型 2.浮点类型 float数据类型用于较小的浮点数,因为它要求的精度较低. double数据类型比 ...
- js获取光标位置并插入内容
先来几个网上找的参考资源,我爱互联网,互联网使我变得更加强大. https://blog.csdn.net/mafan121/article/details/78519348 详细篇,该作者很用心的解 ...