Fiber NetworkTime Limit: 1000 MS Memory Limit: 65536 K Total Submissions: 2725 Accepted: 1252 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 cable S 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 D 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-this is also a typical floyd. The interesting part of this question lies in the processing of input data. This is the key. The others are actually very simple. I am stupid. It took me half a day to understand this question. The following code is used:
# Include <cstdio> # include <cstring> # include <iostream> # include <algorithm> using namespace std; int m [201] [201]; // matrix int n in floyd; int I, j, k; // Loop Variable void floyd () {// template 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]); // here is the key to this question. The requirement here is not the shortest path, and it is required to have some points that can meet the conditions, so you need to change the formula} int main () {int A, B; char str [100]; char ch; while (scanf ("% d", & n) {memset (m, 0, sizeof (m); whi Le (scanf ("% 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 ')); // This is the data processing technique I learned in this question. By first converting the input data into binary, the elements in the matrix are evaluated by bit or, remember: | not |, the author is kneeling here for an hour} floyd (); while (scanf ("% 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 ;}