POJ 2579 Fiber Network(状态压缩+Floyd)
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 3328 | Accepted: 1532 |
Description
Now, service providers, who want to send data from node A to node B
are curious, which company is able to provide the necessary connections.
Help the providers by answering their queries.
Input
input contains several test cases. Each test case starts with the
number of nodes of the network n. Input is terminated by n=0. Otherwise,
1<=n<=200. Nodes have the numbers 1, ..., n. Then follows a list
of connections. Every connection starts with two numbers A, B. The list
of connections is terminated by A=B=0. Otherwise, 1<=A,B<=n, and
they denote the start and the endpoint of the unidirectional connection,
respectively. For every connection, the two nodes are followed by the
companies that have a connection from node A to node B. A company is
identified by a lower-case letter. The set of companies having a
connection is just a word composed of lower-case letters.
After the list of connections, each test case is completed by a list
of queries. Each query consists of two numbers A, B. The list (and with
it the test case) is terminated by A=B=0. Otherwise, 1<=A,B<=n,
and they denote the start and the endpoint of the query. You may assume
that no connection and no query contains identical start and end nodes.
Output
each query in every test case generate a line containing the
identifiers of all the companies, that can route data packages on their
own connections from the start node to the end node of the query. If
there are no companies, output "-" instead. Output a blank line after
each test case.

Sample Input
- 3
- 1 2 abc
- 2 3 ad
- 1 3 b
- 3 1 de
- 0 0
- 1 3
- 2 1
- 3 2
- 0 0
- 2
- 1 2 z
- 0 0
- 1 2
- 2 1
- 0 0
- 0
Sample Output
- ab
- d
- -
- z
- -
Source
- #include <cstdio>
- #include <iostream>
- #include <cstdlib>
- #include <algorithm>
- #include <ctime>
- #include <cmath>
- #include <string>
- #include <cstring>
- #include <stack>
- #include <queue>
- #include <list>
- #include <vector>
- #include <map>
- #include <set>
- using namespace std;
- const int INF = 0x3f3f3f3f;
- const double eps = 1e-;
- const double PI = acos(-1.0);
- const int maxn = ;
- int a[maxn][maxn];
- int main()
- {
- int n;
- while(~scanf("%d", &n)&&n)
- {
- int u, v;
- memset(a, , sizeof(a));
- while(scanf("%d%d", &u, &v)&& (u+v))
- {
- char s[];
- scanf("%s", s);
- for(int i = ; i < strlen(s); i++)
- a[u][v] |= <<(s[i] - 'a');
- }
- for(int k = ; k <= n; k++)
- for(int i = ; i <= n; i++)
- for(int j = ; j <= n; j++)
- a[i][j] |= a[i][k] & a[k][j];
- while(scanf("%d%d", &u, &v) && (u+v))
- {
- for(int i = 'a'; i <= 'z'; i++)
- if(a[u][v] & ( << (i-'a')))
- printf("%c",i);
- if(!a[u][v])
- printf("%c",'-');
- puts("");
- }
- puts("");
- }
- return ;
- }
POJ 2579 Fiber Network(状态压缩+Floyd)的更多相关文章
- Fiber Network ZOJ 1967(Floyd+二进制状态压缩)
Description Several startup companies have decided to build a better Internet, called the "Fibe ...
- POJ 2570 Fiber Network
Description Several startup companies have decided to build a better Internet, called the "Fibe ...
- POJ 3254. Corn Fields 状态压缩DP (入门级)
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9806 Accepted: 5185 Descr ...
- POJ 3691 (AC自动机+状态压缩DP)
题目链接: http://poj.org/problem?id=3691 题目大意:给定N个致病DNA片段以及一个最终DNA片段.问最终DNA片段最少修改多少个字符,使得不包含任一致病DNA. 解题 ...
- [POJ 2923] Relocation (动态规划 状态压缩)
题目链接:http://poj.org/problem?id=2923 题目的大概意思是,有两辆车a和b,a车的最大承重为A,b车的最大承重为B.有n个家具需要从一个地方搬运到另一个地方,两辆车同时开 ...
- POJ 1321 棋盘问题(状态压缩DP)
不总结的话, 同一个地方会 WA 到死 思路: 状态压缩 DP. 1. s 表示压缩状态, 若第 i 列放了棋子, 那么该列置 1, 否则该列置 0. 假如 s = 3(0x011) 那么表示棋盘的第 ...
- POJ 2046 Gap 搜索- 状态压缩
题目地址: http://poj.org/problem?id=2046 一道搜索状态压缩的题目,关键是怎样hash. AC代码: #include <iostream> #include ...
- HDU 5418——Victor and World——————【状态压缩+floyd】
Victor and World Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/131072 K (Java/Other ...
- POJ 2570 Fiber Network(最短路 二进制处理)
题目翻译 一些公司决定搭建一个更快的网络.称为"光纤网". 他们已经在全世界建立了很多网站.这 些网站的作用类似于路由器.不幸的是,这些公司在关于网站之间的接线问题上存在争论,这样 ...
随机推荐
- poj 1149 pigs(最大流)
题目大意:迈克在农场工作,农场有 m 个猪舍,每个猪舍有若干只猪,但是迈克不能打开任何一间猪舍.有 n 个顾客前来购买,每个顾客有最大的购买数量,每个顾客可以购买某些猪舍的猪,且顾客可以打开这些猪舍, ...
- 理解mcelog如何工作
前言 本文,带你了解几个问题? 本文重点,主要看案例2,带你很好的理解mcelog如何工作的? mcelog的干什么的? mcelog 是 x86 的 Linux 系统上用来 检查硬件错误,特别是内存 ...
- hdu 5311 Hidden String(find,substr)
Problem Description Today is the 1st anniversary of BestCoder. Soda, the contest manager, gets a str ...
- POJ 2524 并查集
Ubiquitous Religions Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 23580 Accepted: 1160 ...
- Linux入门基础 #8:Linux拓展权限
本文出自 http://blog.csdn.net/shuangde800 ------------------------------------------------------------ ...
- 机器学习实战笔记5(logistic回归)
1:简单概念描写叙述 如果如今有一些数据点,我们用一条直线对这些点进行拟合(改线称为最佳拟合直线),这个拟合过程就称为回归.训练分类器就是为了寻找最佳拟合參数,使用的是最优化算法. 基于sigmoid ...
- [IDEA学习笔记][keymap]
一个总站: http://www.youmeek.com/ 常用的快捷键keymap 提示: ctrl+N:快速打开一个类 Ctrl+P 方法参数提示显示 Ctrl+J 提示自定义模板 Ctrl+O ...
- 《JavaScript 闯关记》之 DOM(下)
Element 类型 除了 Document 类型之外,Element 类型就要算是 Web 编程中最常用的类型了.Element 类型用于表现 XML 或 HTML 元素,提供了对元素标签名.子节点 ...
- linux上备份Oracle时EXP-00091的错误解决方法
unix/linux上备份Oracle时EXP-00091的错误解决方法 unix/linux上备份数据时的错误解决方法 EXP-00091: Exporting questionable stati ...
- SET XACT_ABORT 的用法[转]
SET XACT_ABORT指定当 Transact-SQL 语句产生运行时错误时,Microsoft® SQL Server™ 是否自动回滚当前事务. 语法 SET XACT_ABORT { ON ...