UVA10199- Tourist Guide(割点)
题意: 给出一张无向图,找出割点,字典序输出割点的名字。
思路:简单的割点的求解,用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(割点)的更多相关文章
- [uva] 10099 - The Tourist Guide
10099 - The Tourist Guide 题目页:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemi ...
- UVa10099_The Tourist Guide(最短路/floyd)(小白书图论专题)
解题报告 题意: 有一个旅游团如今去出游玩,如今有n个城市,m条路.因为每一条路上面规定了最多可以通过的人数,如今想问这个旅游团人数已知的情况下最少须要运送几趟 思路: 求出发点到终点全部路其中最小值 ...
- 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 ...
- CodeForces 589H Tourist Guide
传送门 题目大意 给定$n$个点$m$条边的无向图,有$K$个关键点,你要尽可能的让这些关键点两两匹配,使得所有点对之间可以通过简单路径连接且任意两个简单路径没有重复的边(可以是共同经过一个点),输出 ...
- UVA题目分类
题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...
- (Step1-500题)UVaOJ+算法竞赛入门经典+挑战编程+USACO
http://www.cnblogs.com/sxiszero/p/3618737.html 下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年 ...
- ACM训练计划step 1 [非原创]
(Step1-500题)UVaOJ+算法竞赛入门经典+挑战编程+USACO 下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成 ...
- UESTC-888-Absurdistan Roads(kruskal+floyd)
The people of Absurdistan discovered how to build roads only last year. After the discovery, every c ...
- 算法竞赛入门经典+挑战编程+USACO
下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成.打牢基础,厚积薄发. 一.UVaOJ http://uva.onlinej ...
随机推荐
- Hibernate框架大配置关联小配置
1 <?xml version='1.0' encoding='utf-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-// ...
- POJ3260:The Fewest Coins(混合背包)
Description Farmer John has gone to town to buy some farm supplies. Being a very efficient man, he a ...
- OCP-1Z0-051-题目解析-第6题
6. Examine the structure of the SHIPMENTS table: name Null Type PO_ID ...
- unity4.x for mac破解(含Unity全版本号破解)
声明,破解方式及工具,均来源于国外互联网.仅供交流学习使用! 国外一个大仙做的破解.这位大侠实在是牛,全版本号跟进,win和mac的破解包都有.win下有类似于注冊机的Patch,mac下有crack ...
- MFC读写配置文件
void CFileTextDoc::OnIniread() { // TODO: Add your command handler code here CString strStudName; ...
- zabbix-check of pre-requisites
LAMP搭建完成后,访问http://ip/zabbix,在检查环境界面,有的检查项目提示fail.常见如下:zabbix:Check of pre-requisites1.PHP bcmath fa ...
- 移动前端开发之 viewport 的深入理解
移动设备上进行网页的重构或开发,首先得搞明白的就是移动设备上的viewport了,只有明白了viewport的概念以及弄清楚了跟viewport有关的meta标签的使用,才能更好地让我们的网页适配或响 ...
- UINavigationController 导航控制器
一.导航视图控制器 1.管理视图控制器 2.控制视图控制器之间的跳转 3.是以压栈和出栈的形式来管理视图控制器 4.导航视图控制器必须要设置根视图控制器 5.导航是视图控制器包含UINavigatio ...
- hdu1219
Problem Description Ignatius is doing his homework now. The teacher gives him some articles and asks ...
- Sigmoid function in NN
X = [ones(m, ) X]; temp = X * Theta1'; t = size(temp, ); temp = [ones(t, ) temp]; h = temp * Theta2' ...