求割掉一个点后的连通分量个数最多的m个点

It is the year 95 ACM (After the Crash of Microsoft). After many years of peace, a war has broken out. Your nation, the island of Evergreen Macros And Confusing Shortcuts (EMACS), is defending itself against the railway empire ruled by Visually Impaired Machinists (VIM). In the days leading up to the outbreak of war, your government devoted a great deal of resources toward gathering intelligence on VIM. It discovered the following:
• The empire has a large network of railway stations connected by bidirectional tracks.
• Before the outbreak of the war, each railway station was directly connected to at most 10 other stations. • Information is constantly being exchanged in VIM, but, due to a design flaw, the only way it can be exchanged is to send the messages by train. Before the outbreak of the war, it was possible to send a message by train from any station to any other station. • As a last resort, the empire’s central command can send messages by carrier pigeon, but it tries to avoid this at all costs, as the only pigeons suitable for the job must be imported, at great expense, from the far-away land of Pigeons In Courier Outfits (PICO). • Once a pigeon has delivered a message to a railway station, it must rest, and thus cannot be used again. If a pigeon has delivered a broadcast message to a particular station, the message is passed on, if possible, by train.
Based on this information, the government of EMACS has come up with a plan to disrupt the activities of the evil empire. They will send bomber planes to bomb the railway stations, thus hampering communications in the empire. This will necessitate to acquire many carrier pigeons by the empire, distracting it from its deadly wartime activities. Unfortunately, your government spent so much money on gathering intelligence that it has a very limited amount left to build bombs. As a result, it can bomb only one target. You have been charged with the task of determining the best candidate railway stations in the empire to bomb, based on their “pigeon value”. The “pigeon value” of a station is the minimum number of pigeons that after bombing this station, will be required to broadcast a message from the empire central command to all non-bombed stations. The location of the empire central command is unknown but we know that it is not located at a railway station. This implies, that when the central command needs to send a message to some non-bombed station they have to use at least one pigeon and then the message can be further transmitted by the railway.
Input
The input file contains several test cases. The data for each case begins with a line containing the following two integers: • n the number of railway stations in the empire (3 ≤ n ≤ 10000). The stations will be numbered starting from 0, up to n−1 • m the number of stations to be identified as candidate bombing targets (1 ≤ m ≤ n). Next few lines consists of pairs of integers. Each pair (x,y) indicates the presence of a bidirectional railway line connecting railway stations x and y. This sequence is terminated by a line containing two minus 1 as shown in the sample input. Input is terminated by a case where the value of n = m = 0. This case should not be processed.
Output
For each case of input the output should give m most desirable railway stations to bomb. There should be exactly m lines, each with two integers separated by a single space. The first integer on each line will be the number of a railway station, and the second will be the “pigeon value” of the station. This list should be sorted, first by “pigeon value”, in descending order, and within the same “pigeon value” by railway station numbers, in ascending order. Print a blank line after the output for each set of input.
Sample Input
8 4

0 4

1 2

2 3

2 4

3 5

3 6

3 7

6 7

-1 -1

0 0
Sample Output
2 3

3 3

4 2

0 1

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXN=10009;
const int MAXM=1000009;
struct Edge
{int to,next;
}edge[MAXM];
int head[MAXN],tot;
int Low[MAXN],DFN[MAXN];
int Index;
bool cut[MAXN];
struct node
{int id,num;
}add_block[MAXN];
void addedge(int u,int v)
{edge[tot].to=v;edge[tot].next = head[u];head[u]=tot++;//cout<<head[u]<<endl;
}
void Tarjan(int u,int pre)
{int v;Low[u] = DFN[u]=++Index;int son=0;for(int i = head[u];i != -1;i = edge[i].next){v = edge[i].to;if(v == pre)continue;if(!DFN[v]){son++;Tarjan(v,u);if(Low[u]> Low[v])Low[u] = Low[v];if(u != pre && Low[v] >= DFN[u])add_block[u].num++;}else if( Low[u] > DFN[v])Low[u] = DFN[v];}if(u==pre) add_block[u].num=son-1;
}
int cmp(node a,node b)
{if(a.num!=b.num)return a.num>b.num;elsereturn a.id<b.id;
}
int main()
{int n,u,v,m;while(~scanf("%d %d",&n,&m)&&n&&m){tot=0;Index=0;memset(head,-1,sizeof(head));memset(cut,0,sizeof(cut));memset(DFN,0,sizeof(DFN));for(int i=0;i<n;i++){add_block[i].id=i;add_block[i].num=0;}while(scanf("%d %d",&u,&v)&&u!=-1&&v!=-1){addedge(u,v);addedge(v,u);}for(int i=0;i<n;i++)if(!DFN[i])Tarjan(i,i);sort(add_block,add_block+n,cmp);for(int i=0;i<m;i++)printf("%d %d\n",add_block[i].id,add_block[i].num+1);printf("\n");}return 0;
}

Doves and bombs UVA - 10765相关推荐

  1. UVA 10765 Doves and bombs 割点

    最近好懒,堆了好多题没写题解.. 原题链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8& ...

  2. UVA,10765 Doves and bombs

    题意:给你n个点,然后你要算出删除每个点后有多少个联通块,然后输出前m个,顺序是优先输出形成联通块多的,假如有数量相同,优先输出先输入的. 思路:参考了一下别人的思路,用tarjan时就可以求出联通块 ...

  3. UVA10765 Doves and bombs(双连通分量)

    Problem 每个点的权为删除这个点后图中连通块的个数,求权值前m大的点. Solution 求点-双连通分量,一个点的权值为总连通块数+该点出现在不同点连通分量的次数-1. 该点出现在不同点连通分 ...

  4. [kuangbin]各种各样的题单

    [kuangbin]各种各样的题单 专题1 简单搜索 POJ 1321 POJ 2251 POJ 3278 POJ 3279 POJ 1426 POJ 3126 POJ 3087 POJ 3414 F ...

  5. 无向图的割顶、桥、BCC和eBCC相关

    几个例题代码待填 割顶:若去掉一个点和与这个点相连的边后,图不再连通,则这个点是割顶. ​ 求法:若节点\(u\)存在一棵子树\(v\)满足\(v\)中所有节点的回边都指向\(u\)及以下的节点(即\ ...

  6. 图论算法与模型(训练指南题库)

    一.基础题目 1.UVA 11624 Fire!迷宫问题 多源BFS 题意: 帮助joe走出一个大火蔓延的迷宫,其中joe每分钟可往上下左右四个方向之一走,所有着火的格子都会蔓延(空格与着火格有公共边 ...

  7. [搜索]UVa 129 困难的串

    题意:将一个包含两个相邻的重复子串的子串,称为"容易的串",其他为"困难的串". 输入正整数n和l,输出由前l个字符组成的,字典序第n小的困难的串. 输入样例: ...

  8. uva 401.Palindromes

    题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

  9. Uva 3767 Dynamic len(set(a[L:R])) 树套树

    Dynamic len(set(a[L:R])) Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 https://uva.onlinejudge.org/in ...

最新文章

  1. html主动发起重新布局,重启连不上网
  2. sql 怎样 得到 的客户端的ip地址_怎样用卷发棒?正确用法大揭密-装修攻略
  3. 调链接_硬核科普 | 三根弹簧让你链接宇宙的混响效果器?!
  4. CSS3盒模型display:box详解
  5. 客户端手册_山东省税务局社保费管理客户端企业缴费操作手册
  6. Oracle-PFILE和SPFILE解读
  7. aes c# java_AES加密,C#和java相同
  8. Hadoop分布式环境下的数据抽样
  9. Dalvik/ART(ANDROID)中的多线程机制(2)
  10. 持续集成配置之Nuget
  11. c语言补全程序,跪求高手解答简单的程序补全题~!
  12. (数据库系统概论|王珊)第十章数据库恢复技术-第四、五、六、七节:数据库恢复技术和数据库镜像
  13. Android批量图片载入经典系列——使用LruCache、AsyncTask缓存并异步载入图片
  14. 运算、函数、数组的了解
  15. 27. Location reload() 方法
  16. 服务器显示AL024是什么意思,云端时代云终端快速部署指南(S11AL).ppt
  17. DeepMind利用AI分析动物行为,可正确识别50种大型物种
  18. Ruby Rails开发资源
  19. 大数据第一季--Hadoop(day5)-徐培成-专题视频课程
  20. android 手机 平板同屏,酷乐视Q6投影仪Android手机/平板同屏方法汇总

热门文章

  1. docker部署微服务项目
  2. android编辑图片和文字,微商图片和文字编辑器
  3. Tensorflow 2.0 视频分类(四) C3D 3D convolutional Networks
  4. <UDP网络编程>——《计算机网络》
  5. Android图形系统之HWComposer
  6. Java注释:单行、多行和文档注释
  7. redis高可用:keepalived+redis主从部署
  8. html中submit和button的区别(总结)
  9. Python图像识别-Opencv02 二值图像、灰度图像以及彩色图像
  10. “代理服务出现问题,或者地址有误“解决方案