题目翻译

一些公司决定搭建一个更快的网络。称为“光纤网”。

他们已经在全世界建立了很多网站。这 些网站的作用类似于路由器。不幸的是,这些公司在关于网站之间的接线问题上存在争论,这样“光纤网”项目就被迫终止了,留下的是每一个公司自己在某些网站之间铺设的线路。 如今,Internet 服务供应商。当想从网站 A传送数据到网站 B,就感到困惑了。究竟哪个公司 可以提供必要的连接。

请帮助供应商回答他们的查询。查询全部可以提供从网站
A到站定 B的线 路连接的公司。

输入描写叙述:

输入文件包括多个測试数据。每一个測试数据第 1行为一个整数 n,代表网络中网站的个数。n = 0 代表输入结束。否则 n的范围为:1≤n≤200。网站的编号为 1, …, n。

接下来列出了这些站 点之间的连接。每对连接占一行,首先是两个整数 A和B,A = B = 0 代表连接列表结束,否则 A、 B的范围为:1≤A, B≤n,表示网站 A和网站 B之间的单向连接;每行后面列出了拥有网站
A到 B之间连接的公司。公司用小写字母标识,多个公司的集合为包括小写字母的字符串。

连接列表之后。是供应商查询的列表。每一个查询包括两个整数 A和B,A = B = 0 代表查询列 表结束,也代表整个測试数据结束,否则 A、B 的范围为:1≤A, B≤n,代表查询的起始和终止 网站。

假定不论什么一对连接和查询的两个网站都不同样。

输出描写叙述:

对測试数据中的每一个查询,输出一行,为满足下面条件的全部公司的标识:这些公司能够通 过自己的线路为供应商提供从查询的起始网站到终止网站的数据通路。假设没有满足条件的公司, 则仅输出字符"-"。每一个測试数据的输出之后输出一个空行。

公司最多有26个  能够用2进制来表示网站间的连接关系  假设提供网站 1 到网站 2 的连接的公司集合为{ 'a', 'b', 'c' },能够用 “00000000000000000000000000000111”表示,提供网站 2到网站 3的连接的公司集合为{ 'a', 'd' },用“00000000000000000000000000001001”表示,这两个整数进行二进制与运算后
 得到“00000000000000000000000000000001”,表示通过中间网站 2,提供网站 1到网站 3的连 接的公司集合为{ 'a' }。

这样就floyd进行处理就类似最短路问题了

#include<cstdio>
#include<cstring>
using namespace std;
const int N = 205;
int d[N][N], n; void floyd()
{
for(int k = 1; k <= n; ++k)
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= n; ++j)
d[i][j] |= (d[i][k] & d[k][j]); } int main()
{
int a, b;
char s[30];
while(scanf("%d", &n), n)
{
memset(d, 0, sizeof(d));
while(scanf("%d%d", &a, &b), a)
{
scanf("%s", s);
for(int i = 0; s[i] != '\0'; ++i)
d[a][b] = d[a][b] | (1 << s[i] - 'a');
}
floyd();
while(scanf("%d%d", &a, &b), a)
{
for(char c = 'a'; c <= 'z'; ++c)
if(d[a][b] & (1 << c - 'a')) printf("%c", c);
if(d[a][b] == 0) printf("-");
printf("\n");
}
printf("\n");
}
return 0;
}

Fiber Network

Description

Several startup companies have decided to build a better Internet, called the "FiberNet". They have already installed many nodes that act as routers all around the world. Unfortunately, they
started to quarrel about the connecting lines, and ended up with every company laying its own set of cables between some of the nodes. 

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

The 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

For 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
-

POJ 2570 Fiber Network(最短路 二进制处理)的更多相关文章

  1. POJ 2570 Fiber Network

    Description Several startup companies have decided to build a better Internet, called the "Fibe ...

  2. ZOJ 1967 POJ 2570 Fiber Network

    枚举起点和公司,每次用DFS跑一遍图,预处理出所有的答案.询问的时候很快就能得到答案. #include<cstdio> #include<cmath> #include< ...

  3. poj 2570 Fiber Network(floyd)

    #include<stdio.h> #include<string.h> #include<algorithm> using namespace std; int ...

  4. POJ 2579 Fiber Network(状态压缩+Floyd)

    Fiber Network Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3328   Accepted: 1532 Des ...

  5. POJ 1459 Power Network / HIT 1228 Power Network / UVAlive 2760 Power Network / ZOJ 1734 Power Network / FZU 1161 (网络流,最大流)

    POJ 1459 Power Network / HIT 1228 Power Network / UVAlive 2760 Power Network / ZOJ 1734 Power Networ ...

  6. 【POJ 3694】 Network(割边&lt;桥&gt;+LCA)

    [POJ 3694] Network(割边+LCA) Network Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 7971 ...

  7. POJ 3635 - Full Tank? - [最短路变形][手写二叉堆优化Dijkstra][配对堆优化Dijkstra]

    题目链接:http://poj.org/problem?id=3635 题意题解等均参考:POJ 3635 - Full Tank? - [最短路变形][优先队列优化Dijkstra]. 一些口胡: ...

  8. POJ 2236 Wireless Network ||POJ 1703 Find them, Catch them 并查集

    POJ 2236 Wireless Network http://poj.org/problem?id=2236 题目大意: 给你N台损坏的电脑坐标,这些电脑只能与不超过距离d的电脑通信,但如果x和y ...

  9. zoj 1967 Fiber Network/poj 2570

    题意就是 给你 n个点 m条边 每条边有些公司支持 问 a点到b点的路径有哪些公司可以支持 这里是一条路径中要每段路上都要有该公司支持 才算合格的一个公司// floyd 加 位运算// 将每个字符当 ...

随机推荐

  1. Django -聚合分组,FQ操作, cookie, session

    一. 聚合查询和分组 1. 聚合 aggregate(*args, **kwargs) 对一组数据进行统计分析, 通过对QuerySet进行计算, 返回一个聚合值得字典. arrgregate()中每 ...

  2. fetch 如何请求数据

    fetch 如何请求数据 在 传统Ajax 时代,进行 API 等网络请求都是通过XMLHttpRequest或者封装后的框架进行网络请求,然而配置和调用方式非常混乱,对于刚入门的新手并不友好 二 与 ...

  3. 【【henuacm2016级暑期训练】动态规划专题 E】Destroying Roads

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 首先. 这张图是无向无权图. 因此任意两点之间的最短路可以通过N^2的bfs轻易算出来. 即得到d[N+10][N+10] 考虑s[ ...

  4. 从QQ聊天看交流的有效性

    首先让我们看一则约10分钟的QQ群聊天记录.截图例如以下.已经进行了隐私保护. 交流的主体为大二的在校生与刚刚毕业的学长之间的对话,学长參加过培训,在校学弟想了解一下.故有了以下的交流.(从上到下,从 ...

  5. mybatis和hibernate的区别【转】

    第一章     Hibernate与MyBatisHibernate 是当前最流行的O/R mapping框架,它出身于sf.net,现在已经成为Jboss的一部分. Mybatis 是另外一种优秀的 ...

  6. 从ORA-27300,ORA-27301到ORA-00064

        近期因为session数量添加,须要调整session,也就是要调整process參数. 看是比較简单的一个问题,却遭遇了ORA-27300,ORA-27301.因为这个涉及到了有关内核參数k ...

  7. IOS7 textkit 的相关

    去年基于5.0开发的时候.自己用coreText编写了一个富文本,全部的效果都实现的非常好.可是没有去測试效率.只是在cell重用的时候表现不错.在4s上面也不会卡顿. 唯一一个问题就是,在使用AL的 ...

  8. awk双文件互相匹配查找

    awk双文件互相匹配查找 要求: 文件a:  10/05766798607,11/20050325191329,29/0.1,14/05766798607  10/05767158557,11/200 ...

  9. linux修改history记录数

    在linux系统下.history命令会保存多少条命令呢?曾在一本书上说,如果注销系统,那么会将所有的历史命令都定入到~/.bash_history, 但只保留1000条命令(这个是由默认的shell ...

  10. MongoDB基本概念和安装配置

    基本概念 MongoDB直接存储JSON. 有了NoSQL数据库之后,可以直接在业务层将数据按照指定的结构进行存储. NO SQL NoSQL 1 数据库 数据库 2 表 集合 3 行 文档 4 列 ...