好久没发博客了啊!自我反省1s。。。今天再捡起来。

这个题是一道有一点特殊的tarjan,用tarjan维护子树大小,然后判断是否有边多次连接,(就是非树边),然后就进行乘法计算就行了。

具体在代码里讲:

题干:

在Byteotia有n个城镇。 一些城镇之间由无向边连接。 在城镇外没有十字路口,尽管可能有桥,隧道或者高架公路(反正不考虑这些)。每两个城镇之间至多只有一条直接连接的道路。人们可以从任意一个城镇直接或间接到达另一个城镇。 每个城镇都有一个公民,他们被孤独所困扰。事实证明,每个公民都想拜访其他所有公民一次(在主人所在的城镇)。所以,一共会有n*(n-)次拜访。

不幸的是,一个程序员总罢工正在进行中,那些程序员迫切要求购买某个软件。

作为抗议行动,程序员们计划封锁一些城镇,阻止人们进入,离开或者路过那里。

正如我们所说,他们正在讨论选择哪些城镇会导致最严重的后果。

编写一个程序:

读入Byteotia的道路系统,对于每个被决定的城镇,如果它被封锁,有多少访问不会发生,输出结果。
输入输出格式 第一行读入n,m,分别是城镇数目和道路数目 城镇编号1~n 接下来m行每行两个数字a,b,表示a和b之间有有一条无向边 输出n行,每行一个数字,为第i个城镇被锁时不能发生的访问的数量。

代码:

#include<iostream>
#include<cstdio>
#include<cmath>
#include<ctime>
#include<queue>
#include<algorithm>
#include<cstring>
using namespace std;
#define duke(i,a,n) for(register int i = a;i <= n;i++)
#define lv(i,a,n) for(register int i = a;i >= n;i--)
#define clean(a) memset(a,0,sizeof(a))
const int INF = << ;
typedef long long ll;
typedef double db;
template <class T>
void read(T &x)
{
char c;
bool op = ;
while(c = getchar(), c < '' || c > '')
if(c == '-') op = ;
x = c - '';
while(c = getchar(), c >= '' && c <= '')
x = x * + c - '';
if(op) x = -x;
}
template <class T>
void write(T x)
{
if(x < ) putchar('-'), x = -x;
if(x >= ) write(x / );
putchar('' + x % );
}
struct node
{
int l,r,nxt;
}a[];
int len = ,lst[],n,m;
int dfn[],low[],cnt = ,siz[];
ll ans[];
void add(int x,int y)
{
a[++len].l = x;
a[len].r = y;
a[len].nxt = lst[x];
lst[x] = len;
}
void tarjan(int x)
{
dfn[x] = low[x] = ++cnt;
siz[x] = ;
int z = ;
for(int k = lst[x];k;k = a[k].nxt)
{
int y = a[k].r;
if(!dfn[y])
{
tarjan(y);
low[x] = min(low[x],low[y]);
siz[x] += siz[y];
if(dfn[x] <= low[y]) //是否有非树边连接上下两端
{
ans[x] += (ll)z * siz[y];
z += siz[y];
}
}
else
low[x] = min(low[x],dfn[y]);
}
ans[x] += (ll)z * (n - z - );//自己那也去不了
}
int main()
{
read(n);read(m);
duke(i,,m)
{
int x,y;
read(x);read(y);
add(x,y);
add(y,x);
}
/*duke(i,1,n)
{
if(!dfn[i])
{
tarjan(i);
}
}*/
tarjan();//一定是连通的,所以不用循环
duke(i,,n)
{
printf("%lld\n",(ans[i] + n - ) << );
}
return ;
}

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

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

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

  2. [POI2008]BLO(Tarjan)

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

  3. BZOJ 1123 [POI2008]BLO(Tarjan算法)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1123 [题目大意] Byteotia城市有n个towns,m条双向roads. 每条r ...

  4. 【BZOJ1123】 [POI2008]BLO (tarjan)

    tarjan判断割点...拿掉一个点之后,会被分成若干个联通块,用节点个数和统计一下他们相互不能到达的个数就好. ; maxm=; type edgetype=record toward,next:l ...

  5. 【bzoj1123】【[POI2008]BLO】tarjan判割点

    (上不了p站我要死了,侵权度娘背锅) Description Byteotia城市有n个 towns m条双向roads. 每条 road 连接 两个不同的 towns ,没有重复的road. 所有t ...

  6. P3469 [POI2008]BLO-Blockade 割点 tarjan

    题意 给定一个无向图,问删掉点i,图中相连的有序对数.(pair<x, y> , x != y);求每个点对应的答案 思路 首先我们可以发现,如果这个点不是割点,那么答案就是n-1,如果是 ...

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

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

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

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

  9. P3469 [POI2008]BLO-Blockade(Tarjan 割点)

    P3469 [POI2008]BLO-Blockade 题意翻译 在Byteotia有n个城镇. 一些城镇之间由无向边连接. 在城镇外没有十字路口,尽管可能有桥,隧道或者高架公路(反正不考虑这些).每 ...

  10. BZOJ 1123: [POI2008]BLO

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

随机推荐

  1. EasyUI_datagrid

    案例一丶jquery.easyui.min.js:10631 Uncaught TypeError: this.renderEmptyRow is not a function 解决方法:datagr ...

  2. 小程序wx:key = “{{*this}}”报错

    解决方案:改为 wx:key = "*this"

  3. 四角递推(CF Working out,动态规划递推)

    题目:假如有A,B两个人,在一个m*n的矩阵,然后A在(1,1),B在(m,1),A要走到(m,n),B要走到(1,n),两人走的过程中可以捡起格子上的数字,而且两人速度不一样,可以同时到一个点(哪怕 ...

  4. IDLE in Python (Ubuntu)

    To lauch IDLE in the Current Woking Directory >>> usr/bin/idle3 Alt + n  # next command Alt ...

  5. Maven_在Eclipse中执行Maven命令

  6. 【Codeforces 493C】Vasya and Basketball

    [链接] 我是链接,点我呀:) [题意] 题意 [题解] 枚举三分线(离散后)的位置 然后根据预处理的前缀和,快速算出两个队伍的分数. [代码] #include <bits/stdc++.h& ...

  7. nyoj 63 小猴子下落

    小猴子下落 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 有一颗二叉树,最大深度为D,且所有叶子的深度都相同.所有结点从左到右从上到下的编号为1,2,3,····· ...

  8. HDU 4451 容斥原理

    题目大意: n件衣服,m条裤子,k双鞋子进行搭配 妈妈指明了哪些衣服和裤子不能搭配,哪些裤子和鞋子不能搭配,问最后有几种搭配方法 先假设都能搭配 n*m*k 每次遇到衣服和裤子不能搭的,就要减一次k, ...

  9. hdu 2647拓扑排序 结构体模拟容器

    #include<stdio.h> #include<queue> #include<iostream> using namespace std; #define ...

  10. 将Jquery EasyUI中DataGird的数据导入Excel中

    1.第一步获取前台DataGrid中的数据 var rows = $('#tb).datagrid("getRows");            if (rows.length = ...