题目链接

题意: 给出一张无向图,找出割点,字典序输出割点的名字。

思路:简单的割点的求解,用map映射。easy输出。

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <algorithm> using namespace std; const int MAXN = 10005; struct Edge{
int to, next;
bool cut;
}edge[MAXN * 10]; int head[MAXN], tot;
int Low[MAXN], DFN[MAXN];
int Index, cnt;
bool cut[MAXN]; map<string ,int> name;
map<string, int>::iterator iter; string s1, s2; void addedge(int u, int v) {
edge[tot].to = v;
edge[tot].next = head[u];
edge[tot].cut = false;
head[u] = tot++;
} 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]) {
cut[u] = true;
}
}
else if (Low[u] > DFN[v])
Low[u] = DFN[v];
}
if (u == pre && son > 1) cut[u] = true;
} void init() {
memset(head, -1, sizeof(head));
memset(DFN, 0, sizeof(DFN));
memset(cut, false, sizeof(cut));
tot = Index = cnt = 0;
name.clear();
} void solve(int N) {
for (int i = 1; i <= N; i++)
if (!DFN[i])
Tarjan(i, i);
for (int i = 1; i <= N; i++)
if (cut[i])
cnt++;
} int main() {
int n, m, t = 0;
while (scanf("%d", &n) && n) {
init();
for (int i = 1; i <= n; i++) {
cin >> s1;
name[s1] = i;
}
scanf("%d", &m);
for (int i = 0; i < m; i++) {
cin >> s1 >> s2;
addedge(name[s1], name[s2]);
addedge(name[s2], name[s1]);
} solve(n);
if (t) printf("\n");
printf("City map #%d: %d camera(s) found\n", ++t, cnt);
for (iter = name.begin(); iter != name.end(); iter++)
if (cut[iter -> second])
cout << iter -> first << endl;
}
return 0;
}

UVA10199- Tourist Guide(割点)的更多相关文章

  1. [uva] 10099 - The Tourist Guide

    10099 - The Tourist Guide 题目页:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemi ...

  2. UVa10099_The Tourist Guide(最短路/floyd)(小白书图论专题)

    解题报告 题意: 有一个旅游团如今去出游玩,如今有n个城市,m条路.因为每一条路上面规定了最多可以通过的人数,如今想问这个旅游团人数已知的情况下最少须要运送几趟 思路: 求出发点到终点全部路其中最小值 ...

  3. floyd类型题UVa-10099-The Tourist Guide +Frogger POJ - 2253

    The Tourist Guide Mr. G. works as a tourist guide. His current assignment is to take some tourists f ...

  4. CodeForces 589H Tourist Guide

    传送门 题目大意 给定$n$个点$m$条边的无向图,有$K$个关键点,你要尽可能的让这些关键点两两匹配,使得所有点对之间可以通过简单路径连接且任意两个简单路径没有重复的边(可以是共同经过一个点),输出 ...

  5. UVA题目分类

    题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...

  6. (Step1-500题)UVaOJ+算法竞赛入门经典+挑战编程+USACO

    http://www.cnblogs.com/sxiszero/p/3618737.html 下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年 ...

  7. ACM训练计划step 1 [非原创]

    (Step1-500题)UVaOJ+算法竞赛入门经典+挑战编程+USACO 下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成 ...

  8. UESTC-888-Absurdistan Roads(kruskal+floyd)

    The people of Absurdistan discovered how to build roads only last year. After the discovery, every c ...

  9. 算法竞赛入门经典+挑战编程+USACO

    下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成.打牢基础,厚积薄发. 一.UVaOJ http://uva.onlinej ...

随机推荐

  1. [视频] x264 压缩笔记

    转载本站文章请注明,转载自:扶凯[http://www.php-oa.com] 本文链接: http://www.php-oa.com/2009/03/22/x264.html 象x264本身是不能直 ...

  2. 内外连接、组函数、DDL、DML和TCL

    前言 cross join ,是笛卡尔积:nature join 是自然连接. 正文 内外连接 inner join inner join 的inner能够省略. 内连接 在一个表中可以找到在还有一个 ...

  3. php + apache + mysql

    http://archive.apache.org/dist/httpd/binaries/win32/   Apache msi 下载地址

  4. 创建一个简单的配置android编译环境的脚本

    由于有多个Android项目,每个项目配置编译环境时选项都不同,所以尝试写一个sh脚本来完成这个功能.     首先进入bin文件夹,新建一个文件enbuild $ cd ~/bin $ touch ...

  5. SQL日期形式转换

    在SQL Server中,有时存储在数据库中的日期格式和我们需要显示在页面上的格式不相同,我们需要转化成需要的格式. 特在此总结了一下常用的日期格式. --当前时间 SELECT GETDATE(); ...

  6. java静态成员的初始化过程

    public class Price{ final static Price INSTANCE = new Price(2.8); static double initPrice = 20; doub ...

  7. HDU 5815 - Golden Week

    题意: 王国地图为 n 个节点的根树,首都为 1, m 个旅行家要去不同的终点旅游,他们分别有各自的预算,如果路上总费用超过预算就不去了 给每条路定价, 让赚的钱最多 分析:    DP[i][j]表 ...

  8. 导入android项目在eclipse中会报@Override错误

    很多时候导入android项目在eclipse中会报@Override错误,这是由于java编译器的版本不正确,Java 1.5的编译器默认对父类的方法进行覆盖,采用@Override进行说明:但1. ...

  9. Linux安装系统注意事项及系统初始化

      Linux安装系统注意事项 1.分区 学习用途: /boot:200M /swap :内存的1到2倍 /:根据需要分配大小,比如虚拟机下总空间是15G,那么可以分配8——10G跟/分区,如果是生产 ...

  10. Windows,Linux换行知识

    换行符在写文件的时候用得上 Linux: "\n"Windows: "\r\n" 注意:换行符一定要加上双引号,单引号是没有用的.