COGS——T 8. 备用交换机
http://www.cogs.pro/cogs/problem/problem.php?pid=8
★★ 输入文件:gd.in 输出文件:gd.out 简单对比
时间限制:1 s 内存限制:128 MB
- 【问题描述】
第一行,一个整数n,表示共有n个城市(2<=n<=100)
下面有若干行,每行2个数a、b,a、b是城市编号,表示a与b之间有直接通讯线路。
第一行,1个整数m,表示需m个备用交换机,下面有m行,每行有一个整数,表示需配备交换机的城市编号,输出顺序按编号由小到大。如果没有城市需配备备用交换机则输出0。
输入文件名: gd.in
7
1 2
2 3
2 4
3 4
4 5
4 6
4 7
5 6
6 7
输出文件名:gd.out
2
2
4
Tarjan割点模板
#include<algorithm>
#include<cstring>
#include<cstdio>
#define N 1100
using namespace std;
int n,x,y,tim,tot=,ans;
int dfn[N],low[N],head[N],cut_point[N];
int read()
{
int x=,f=; char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-; ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-''; ch=getchar();}
return x*f;
}
struct Edge
{
int to,from,next;
}edge[N];
int add(int x,int y)
{
tot++;
edge[tot].to=y;
edge[tot].next=head[x];
head[x]=tot;
}
int tarjan(int now,int pre)
{
int sum=;bool if_point=false;
dfn[now]=low[now]=++tim;
for(int i=head[now];i;i=edge[i].next)
{
int t=edge[i].to;
if((i^)==pre) continue;
if(!dfn[t])
{
sum++,tarjan(t,i);
low[now]=min(low[now],low[t]);
if(dfn[now]<=low[t]) if_point=true;
}
else low[now]=min(low[now],dfn[t]);
}
if(!pre){if(sum>) ans++,cut_point[now]=true;}
else if(if_point) ans++,cut_point[now]=true;
}
int main()
{
freopen("gd.in","r",stdin);
freopen("gd.out","w",stdout); n=read();
while(scanf("%d%d",&x,&y)==)
add(x,y),add(y,x);
for(int i=;i<=n;i++)
if(!dfn[i]) tarjan(i,);
printf("%d\n",ans);
for(int i=;i<=n;i++)
if(cut_point[i]) printf("%d\n",i);
}
COGS——T 8. 备用交换机的更多相关文章
- cogs——8. 备用交换机
8. 备用交换机 ★★ 输入文件:gd.in 输出文件:gd.out 简单对比时间限制:1 s 内存限制:128 MB [问题描述] n个城市之间有通讯网络,每个城市都有通讯交换机,直 ...
- 备用交换机(cogs 8)
[问题描述] n个城市之间有通讯网络,每个城市都有通讯交换机,直接或间接与其它城市连接.因电子设备容易损坏,需给通讯点配备备用交换机.但备用交换机数量有限,不能全部配备,只能给部分重要城市配置.于是规 ...
- CGOS 8 备用交换机(割点)
题目链接:http://cojs.tk/cogs/problem/problem.php?pid=8 题意:n个城市之间有通讯网络,每个城市都有通讯交换机,直接或间接与其它城市连接.因电子设备容易损坏 ...
- 图的割点 | | jzoj【P1230】 | | gdoi | |备用交换机
写在前面:我真的不知道图的割点是什么.... 看见ftp图论专题里面有个dfnlow的一个文档,于是怀着好奇的心情打开了这个罪恶的word文档,,然后就开始漫长的P1230的征讨战.... 图的割点是 ...
- COGS8 备用交换机
备用交换机 ★★ 输入文件:gd.in 输出文件:gd.out 简单对比时间限制:1 s 内存限制:128 MB [问题描述] n个城市之间有通讯网络,每个城市都有通讯交换机,直接或间 ...
- COGS 08-备用交换机 题解——S.B.S.
8. 备用交换机 ★★ 输入文件:gd.in 输出文件:gd.out 简单对比时间限制:1 s 内存限制:128 MB [问题描述] n个城市之间有通讯网络,每个城市都有通讯交换机,直 ...
- RabbitMQ 备份交换机(alternate-exchange)介绍
RabbitMQ之备份交换机(alternate-exchange) 1.备份交换器,AlternateExchange(AE) 备份交换器是为了实现没有路由到队列的消息,声明交换机的时候添加属性al ...
- {part1}DFN+LOW(tarjan)割点
什么是jarjan? 1)求割点 定义:在无向连通图中,如果去掉一个点/边,剩下的点之间不连通,那么这个点/边就被称为割点/边(或割顶/桥). 意义:由于割点和割边涉及到图的连通性,所以快速地求出割点 ...
- tarjan算法求割点cojs 8
tarjan求割点:cojs 8. 备用交换机 ★★ 输入文件:gd.in 输出文件:gd.out 简单对比时间限制:1 s 内存限制:128 MB [问题描述] n个城市之间有通讯网 ...
随机推荐
- 【原创】JAVA word转html
import java.io.File; import com.jacob.activeX.ActiveXComponent; import com.jacob.com.Dispatch; impor ...
- ModelDriven机制及其运用
ModelDriven 为什么需要ModelDriven 所谓ModelDriven ,意思是直接把实体类当成页面数据的收集对象.比如,有实体类User 如下: package cn.com.lead ...
- (转)Java 虚拟机体系结构
来源:http://hxraid.iteye.com/blog/676235 众所周知,Java源代码被编译器编译成class文件.而并不是底层操作系统可以直接执行的二进制指令(比如Windows O ...
- Linux ping 不通 域名 添加DNS
修改路由配置文件 vi /etc/resolv.conf # Generated by NetworkManager #NDS nameserver 192.168.32.2 redhat7 系统优化 ...
- ActiveMQ maven
http://outofmemory.cn/java/mq/apache-activemq-demo
- groovy : poi 导出 Excel xlsx
參考 file:///poi-3.10-FINAL/docs/spreadsheet/how-to.html#sxssf text2xlsx.groovy 代码例如以下 package xlsx; i ...
- Experience Design for Sexable Forum
Mars March 16, 2015
- Android笔记---点击事件的四种写法
Android 点击事件的四种写法: 1. 以内部类的形式实现 OnClickListener 接口.定义点击事件 class MainActivity extents Activity{ // .. ...
- [poj 2480] Longge's problem 解题报告 (欧拉函数)
题目链接:http://poj.org/problem?id=2480 题目大意: 题解: 我一直很欣赏数学题完美的复杂度 #include<cstring> #include<al ...
- [Poj 1015] Jury Compromise 解题报告 (完全背包)
题目链接:http://poj.org/problem?id=1015 题目: 题解: 我们考虑设计DP状态(因为这很显然是一个完全背包问题不是吗?) dp[j][k]表示在外层循环到i时,选了j个人 ...