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 ...
随机推荐
- python高级编程之装饰器04
from __future__ import with_statement # -*- coding: utf-8 -*- # python:2.x __author__ = 'Administrat ...
- hiberbate的工作原理
hibernate 简介:hibernate是一个开源框架,它是对象关联关系映射的框架,它对JDBC做了轻量级的封装,而我们java程序员可以使用面向对象的思想来操纵数据库.hibernate核心接口 ...
- Android应用程序线程消息循环模型分析
文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/6905587 我们知道,Android应用程序是 ...
- jQuery中的trigger和triggerhandler区别
$("form :input").blur(function(){ // }).keyup(function(){ $(this).triggerHandler("blu ...
- poj1111 DFS
J - 搜索 Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:10000KB 64bit I ...
- hdu 1587
Problem Description As you know, Gardon trid hard for his love-letter, and now he's spending too muc ...
- Ubuntu14.10下解决chromium浏览器无法安装adobe flash的问题
本文参考了一下资源和博客,在此提出表示感谢: http://my.oschina.net/u/209016/blog/290067 http://ubuntuhandbook.org/index.ph ...
- Hibernate事务传播性
事务的几种传播特性 1. PROPAGATION_REQUIRED: 如果存在一个事务,则支持当前事务.如果没有事务则开启 比如说:在UserManager中addUser里开启了,那么在addLog ...
- [Head First Python]6. 定制数据对象:打包代码与数据
相同功能,演进实现 数据文件 sarah2.txt sarah Sweeney,2002-6-17,2:58,2.58,2:39,2-25,2-55,2:54,2.18,2:55,2:55 1- 返回 ...
- php在cli和cgi方式下获取服务器ip的实例
php cli方式下获取服务器ip php内核没有提供这样的命令,需要借助linux中的命令ifconfig来实现,如下两个函数代码: function getServerIp(){ ...