poj2570(最短路+传递闭包)
来源:互联网 发布:古琴调音软件 编辑:程序博客网 时间:2024/05/19 18:00
Fiber Network
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 3063 Accepted: 1403
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.
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.
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
31 2 abc2 3 ad1 3 b3 1 de0 01 32 13 20 021 2 z0 01 22 10 00
Sample Output
abd-z-
Source
Ulm Local 2001
分析:用二进制思想,n<=30正好可以用int的二进制表示,&运算找出共同修建该段道路的公司,|合并所有修建该道路的公司
代码:
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>using namespace std;int dis[300][300];void floyd(int n){int i,j,k;for(k=1;k<=n;k++)for(i=1;i<=n;i++)for(j=1;j<=n;j++)dis[i][j]|=dis[i][k]&dis[k][j];}int main(){int n,a,b,i;char s[35];while(~scanf("%d",&n)&&n){memset(dis,0,sizeof dis);while(scanf("%d%d",&a,&b),a||b){scanf("%s",s);int t=strlen(s);for(i=0;s[i]!='\0';i++)dis[a][b]|=1<<(s[i]-'a');}floyd(n);while(scanf("%d%d",&a,&b),a||b){int num=dis[a][b],cur=0;while(num){if(num%2)printf("%c",cur+'a');num/=2;cur++;}if(!dis[a][b])printf("-");printf("\n");}printf("\n");}return 0;}
0 0
- poj2570(最短路+传递闭包)
- 传递闭包+二进制位运算+floyd(poj2570)
- POJ2570 Fiber Network floyd传递闭包
- poj2570 Fiber Network 最短路floyd
- 任意两点最短路 Floyd-Warshall算法 传递闭包
- Floyd基础知识 多源最短路 && 传递闭包(内含优化) && 最小环
- 最短路经典例题-紫书11-4 Calling Circles(Floyd传递闭包+map+DFS)
- Floyd基础知识 多源最短路 && 传递闭包(内含优化) && 最小环
- 最短路算法包
- 图的多源点最短路问题和传递闭包之Floyd-Warshall算法 By ACReaper
- POJ2570
- 最短路(最短路)
- HDOJ2544 最短路(最短路)
- 最短路 (Dijstra) 最短路
- HDU2544:最短路(最短路)
- hdu2544(最短路)
- 随笔(最短路)
- hdu3790 (最短路)
- 背包问题
- 第三方类库
- 将本地git仓库推送到github上
- cocos2dx 3.x 观察者模式_NotificationCenter的认识
- PostEvent详解
- poj2570(最短路+传递闭包)
- String类的个人总结
- rac 11g 安装错误“Timed outwaiting for the CRS stack to start”的解决
- eclipse新建工作空间,切换工作空间
- 经典面试题:设计包含min函数的栈,O(1)空间实现方法
- lsb_release -a 查询系统版本
- vi 如何插入日期
- 小小自动化
- As Easy As A+B(简单题)