Poj 2570 Fiber Network (Floyd)
Fiber Network
Time Limit:1000 MS |
|
Memory Limit:65536 K |
Total Submissions:3107 |
|
Accepted:1427 |
Description
Several startup companies have decided to build a better Internet, called the "FiberNet ". they have already installed into 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 curous, 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
31 2 abc2 3 ad1 3 b3 1 de0 01 32 13 20 021 2 z0 01 22 10 00
Sample Output
abd-z-
The company uses lowercase letters to indicate a maximum of 26 companies. Therefore, the company can be represented by binary digits.
# Include "stdio. h "# include" string. h "# include" vector "# include" queue "# include" iostream "# include" algorithm "using namespace std; # define N 205 const int inf = (int) 1e10; int g [N] [N]; int main () {int I, j, k, n, a, B; char str [27]; while (scanf ("% d", & n), n) {memset (g, 0, sizeof (g); while (scanf ("% d ", & a, & B), a | B) {scanf ("% s", str); for (I = 0; str [I]! = '\ 0'; I ++) // one of the above represents that the company can connect to, B g [a] [B] | = 1 <(str [I]-'A');} for (k = 1; k <= n; k ++) {for (I = 1; I <= n; I ++) {for (j = 1; j <= n; j ++) {g [I] [j] | = (g [I] [k] & g [k] [j]) ;}} while (scanf ("% d", & a, & B), a | B) {if (! G [a] [B]) {printf ("-\ n"); continue;} for (char I = 'a'; I <= 'Z '; I ++) {if (g [a] [B] & (1 <