POJ 2570 Fiber Network (shortest binary processing)

Source: Internet
Author: User

Topic translation

Some companies decided to build a faster network called the "Fiber network." They have built many sites around the world, and these sites function like routers. Unfortunately, these companies are arguing about the wiring between the sites, so that the "fiber optic network" project is forced to terminate, leaving behind the lines that each company lays on its own site. Now, Internet service providers, when they want to transfer data from site A to site B, are confused as to which company can provide the necessary connectivity. Please help the supplier to answer their queries and inquire about all the companies that can provide line connections from site A to station B.

Input Description:

The input file contains multiple test data. The 1th behavior of each test data is an integer n, representing the number of sites in the network, n = 0 for the input end, otherwise the range of n is: 1≤n≤200. The site is numbered 1, ..., N. The connections between these sites are listed next. For each pair of connections, the first is two integers a and b,a = B = 0 for the end of the connection list, otherwise the range of A, B is: 1≤a, B≤n, represents a one-way connection between site A and site B, a company that has a connection between sites A to B is listed after each line, and the company is identified with a small letter A string containing lowercase letters. After the list of connections, it is the list of vendor queries. Each query contains two integers a and b,a = B = 0 for the end of the query list, and also for the entire test data, otherwise the range of a, B is: 1≤a, B≤n, which represents the starting and ending sites of the query. Assume that any one pair of connections and two sites for the query are not the same.

Output Description:  

For each query in the test data, the output line is the identity of all companies that meet the following criteria: These companies can provide suppliers with their own routes from the start site of the query to the terminating site of the data path. If there are no companies that meet the criteria, only the character "-" is output. Output a blank line after the output of each test data.


There are up to 26 companies that can use 2 to represent the connection relationship between sites if the company collection providing site 1 to site 2 connects to {' A ', ' B ', ' C '}, which can be represented by "00000000000000000000000000000111", providing site 2 to site 3 of the connected company collection is {' A ', ' d '}, denoted by "00000000000000000000000000001001", the two integers are given "00000000000000000000000000000001" after binary and operation, Represents a company collection that provides a connection to site 1 to site 3 through intermediate site 2, {' A '}.

So the Floyd will be treated like the shortest-path problem.

#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]! = ' + '; ++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 has decided to build a better the Internet, called the "Fibernet". They has already installed many nodes, act as routers all around the world. Unfortunately, they started to quarrel on the connecting lines, and ended up with every company laying its own set of C Ables between some of the nodes.
Now, service providers, who want-to-send data from node-A to Node-B is curious, which company was able to provide the nece Ssary 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 was terminated by n=0. Otherwise, 1<=n<=200. Nodes has the numbers 1, ..., N. Then follows a list of connections. Every connection starts with the 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 nodes is followed by the companies, which has a connection from Node A to node B. A company was identified by a lower-case. The set of companies has a connection is just a word composed of lower-case letters.
After the list of connections, all test case are completed by a list of queries. Each query consists of numbers A, B. The list (and with it, the test case) was terminated by a=b=0. Otherwise, 1<=a,b<=n, and they denote the start and the endpoint of the query. 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 the companies, that can route data Packages on their own connections from the start node to the end node of the query. If There is no companies, output "-" instead. Output a blank line after each test case.

Sample Input

2 ABC2 3 AD1 3 B3 1 de0 021 2 z0 01 22 10 00

Sample Output

abd-z-


POJ 2570 Fiber Network (shortest binary processing)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.