Fiber Network
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 2725   Accepted: 1252

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
-

这也是一道典型的floyd。这个题有意思的地方在于对于输入数据的处理,这个是关键,其他的其实非常简单,笔者比较愚蠢,这个处理搞了半天才搞懂。
下面是代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; int m[201][201];//floyd中的矩阵
int n;
int i,j,k;//循环变量 void floyd(){//模板
for(k=1;k<=n;++k)
for(i=1;i<=n;++i)
for(j=1;j<=n;++j)
{
m[i][j]=m[i][j]|(m[i][k]&m[k][j]);//这里是这道题目的关键,这里要求不是最短的路径,而且是要求有哪些点可以满足条件,所以要进行变式
}
} int main(){
int A,B;
char str[100];
char ch;
while(scanf("%d",&n) && n){
memset(m,0,sizeof(m));
while(scanf("%d%d",&A,&B)){
if(A==0&&B==0)
break;
scanf("%s",str);
for(i=0;str[i];++i)
m[A][B]=m[A][B]|(1<<(str[i]-'a'));//这是我在这道题里面学习到的数据处理技巧,通过先将输入的数据转换成二进制,然后在矩阵中的元素按位求或,记住是|而不是||,笔者就是跪在这儿了一个小时
}
floyd();
while(scanf("%d%d",&A,&B)){
if(A==0&&B==0)
break;
for(ch='a';ch<='z';++ch)
{
if(m[A][B]&(1<<ch-'a'))
putchar(ch);
}
if(!m[A][B])
putchar('-');
printf("\n");
}
printf("\n");
}
return 0;
}
												

poj 2263&& zoj1952 floyd的更多相关文章

  1. PoJ(2263),Floyd,最小值中的最大值

    题目链接:http://poj.org/problem?id=2263 题意:题中给出相连通不同城市之间的载货量,要求找到一条从指定起点到终点的路径,并满足载货量最大. #include <io ...

  2. Heavy Cargo POJ 2263 (Floyd传递闭包)

    Description Big Johnsson Trucks Inc. is a company specialized in manufacturing big trucks. Their lat ...

  3. POJ 2263 Heavy Cargo(Floyd + map)

    Heavy Cargo Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3768   Accepted: 2013 Descr ...

  4. POJ 2240Arbitrage(Floyd)

    E - Arbitrage Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submi ...

  5. Poj(1125),Floyd,

    题目链接:http://poj.org/problem?id=1125 多源点最短路中的,最长路的,最短路. 看到这里就懵逼了,解释一下,找到一个源点,使得路最短,(遍历源点),路最短怎么求呢? 就是 ...

  6. POJ 2253 Frogger Floyd

    原题链接:http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissi ...

  7. Poj(3615),Floyd,最大值中的最小值

    题目链接:http://poj.org/problem?id=3615 题意:大致题意:有N个木桩,和M个木桩对之间的高度差(从x跳到y需要往上跳的高度).从x跳跃到y的路径消耗的体力值是路径中的一个 ...

  8. POJ 2253 Frogger floyd算法

    题目:click here 题意: 给出两只青蛙的坐标A.B,和其他的n-2个坐标,任意两坐标间是双向连通的.显然从A到B存在至少一条的通路,每一条通路的元素都是这条通路中前后两个点的距离,这些距离中 ...

  9. Cow Contest POJ - 3660 (floyd 传递闭包)

    N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming contest. As we ...

随机推荐

  1. Expression Language

    EL找不到属性会返回"" page –-  request --- session --- application ------------------------------- ...

  2. thinkPHP的常用配置项

    'URL_PATHINFO_DEPR'=>'-',//修改URL的分隔符 'TMPL_L_DELIM'=>'<{', //修改左定界符 'TMPL_R_DELIM'=>'}&g ...

  3. Fedora安装theano

    Fedora下安装theano Fedora下安装theano Theano的安装依赖很多包,有必须的,有可选的.此外,python版本必须大于2.6,请在shell直接键入python,如果小于2. ...

  4. [LeetCode]题解(python):139-Word Break

    题目来源: https://leetcode.com/problems/word-break/ 题意分析: 给定一个字符串s和一个字典dict,判断s是不是由字典dict里面的元素组成的. 题目思路: ...

  5. JS 节流阀

    JS 节流阀 参考 https://github.com/hahnzhu/read-code-per-day/issues/5 节流阀 节流阀的基本原理 事件函数的执行都记下当前时间, 只有当前时间与 ...

  6. MacOS copy图标shell脚本

    不会shell  同学做的... 可以看见在当前文件夹下创建了一个icons文件夹 最后还压缩了文件夹 #!/bin/bash # readPlist [plist] [key] function r ...

  7. oracle decode函数用法

    DECODE函数是ORACLE PL/SQL是功能强大的函数之中的一个,眼下还仅仅有ORACLE公司的SQL提供了此函数,其它数据库厂商的SQL实现还没有此功能.DECODE有什么用途 呢? 先构造一 ...

  8. Android 自己主动化測试之------ Monkey工具

    尽管 一般公司都有专门的測试人员,可是有时候 免不了 我们既要去开发产品,也要去測试产品,測试产品.有些机械化的 点界面的操作,谷歌已经给我们提供了工具.Monkey, 猴子測试. 什么是Monkey ...

  9. uva 10548 - Find the Right Changes(拓展欧几里得)

    题目链接:uva 10548 - Find the Right Changes 题目大意:给定A,B,C,求x,y,使得xA+yB=C,求有多少种解. 解题思路:拓展欧几里得,保证x,y均大于等于0, ...

  10. flexbox 伸缩布局盒

    Flexbox(伸缩布局盒) 是 CSS3 中一个新的布局模式,为了现代网络中更为复杂的网页需求而设计. Flexbox 由 伸缩容器 和 伸缩项目 组成.通过设置元素的 display 属性为   ...