当前位置: 首页 > news >正文

洛谷P3469 [POI2008]BLO-Blockade

P3469 [POI2008]BLO-Blockade

题目描述

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(n1) 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\ 0001n100 000, 1\le m\le 500\ 0001m500 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 n1a<bn) and denotes a direct road between towns numbered aa and 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.

 

输入输出样例

输入样例#1:  复制
5 5
1 2
2 3
1 3
3 4
4 5
输出样例#1:  复制
8
8
16
14
8
#include<iostream>
#include<cstdio>
#include<cstring>
#define maxn 100010
#ifdef WIN32
#define PLL "%I64d"
#else
#define PLL "%lld"
#endif
using namespace std;
int n,m,cnt;
int dfn[maxn],low[maxn],sz[maxn],head[maxn],num;
long long ans[maxn];
struct node{
    int to,pre;
}e[500010*2];
void Insert(int from,int to){
    e[++num].to=to;
    e[num].pre=head[from];
    head[from]=num;
}
void Tarjan(int now){
    int z=0;sz[now]=1;
    dfn[now]=low[now]=++cnt;
    for(int i=head[now];i;i=e[i].pre){
        int to=e[i].to;
        if(!dfn[to]){
            Tarjan(to);
            sz[now]+=sz[to];
            low[now]=min(low[now],low[to]);
            if(dfn[now]<=low[to]){
                ans[now]+=1LL*z*sz[to];
                z+=sz[to];
            }
        }
        else low[now]=min(low[now],dfn[to]);
    }
    ans[now]+=1LL*z*(n-z-1);
}
int main(){
    scanf("%d%d",&n,&m);
    int x,y;
    for(int i=1;i<=m;i++){
        scanf("%d%d",&x,&y);
        Insert(x,y);Insert(y,x);
    }
    for(int i=1;i<=n;i++)
        if(!dfn[i])Tarjan(i);
    for(int i=1;i<=n;i++)
        printf(PLL"\n",(ans[i]+n-1)<<1);
    return 0;
}

 

转载于:https://www.cnblogs.com/thmyl/p/7742074.html

相关文章:

  • 使用MEMCACHED实现缓存
  • 煤球数目
  • 基本パターン(単一スレッド)
  • css左侧固定宽度,右侧自适应的几种实现方法
  • 可视化查询
  • Alpha 冲刺 (3/10)
  • 用GDB调试程序(一)
  • (转载)深入super,看Python如何解决钻石继承难题
  • 1000. A+B Problem
  • 儿童上网时间管控软件_GreenSurfOnline V0.1 使用说明 (以Windows后台服务形式存在,安装需要有一定电脑操作基础)...
  • 没事儿别优化!
  • Java并发案例04---生产者消费者问题03--使用ReentrantLock
  • Java日志框架-logback的介绍及配置使用方法(纯Java工程)(转)
  • 行外人浅谈“云计算”
  • PE 文件格式 详解 二
  • 【node学习】协程
  • 【笔记】你不知道的JS读书笔记——Promise
  • CentOS 7 修改主机名
  • co.js - 让异步代码同步化
  • CSS居中完全指南——构建CSS居中决策树
  • css属性的继承、初识值、计算值、当前值、应用值
  • Debian下无root权限使用Python访问Oracle
  • linux安装openssl、swoole等扩展的具体步骤
  • 从零到一:用Phaser.js写意地开发小游戏(Chapter 3 - 加载游戏资源)
  • 关于Java中分层中遇到的一些问题
  • 关于使用markdown的方法(引自CSDN教程)
  • 蓝海存储开关机注意事项总结
  • 七牛云 DV OV EV SSL 证书上线,限时折扣低至 6.75 折!
  • 温故知新之javascript面向对象
  • 文本多行溢出显示...之最后一行不到行尾的解决
  • 小李飞刀:SQL题目刷起来!
  • 由插件封装引出的一丢丢思考
  • MyCAT水平分库
  • 翻译 | The Principles of OOD 面向对象设计原则
  • ​油烟净化器电源安全,保障健康餐饮生活
  • #《AI中文版》V3 第 1 章 概述
  • #Linux(Source Insight安装及工程建立)
  • (06)Hive——正则表达式
  • (2)nginx 安装、启停
  • (动态规划)5. 最长回文子串 java解决
  • (二)Linux——Linux常用指令
  • (附源码)ssm高校运动会管理系统 毕业设计 020419
  • (十三)Flask之特殊装饰器详解
  • (图)IntelliTrace Tools 跟踪云端程序
  • (原創) X61用戶,小心你的上蓋!! (NB) (ThinkPad) (X61)
  • (转贴)用VML开发工作流设计器 UCML.NET工作流管理系统
  • ***利用Ms05002溢出找“肉鸡
  • *p++,*(p++),*++p,(*p)++区别?
  • *上位机的定义
  • .bashrc在哪里,alias妙用
  • .NET Core 中的路径问题
  • .NET gRPC 和RESTful简单对比
  • .pop ----remove 删除
  • :中兴通讯为何成功
  • @Bean, @Component, @Configuration简析