Fiber Network
Time Limit: 1000MS |
|
Memory Limit: 65536K |
Total Submissions: 3328 |
|
Accepted: 1532 |
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 PAC Kages 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-
Source
ULM Local 2001 Test instructions: Find all the same places on the right side from the beginning to the end. Idea: First, because the Benquan is the letter is also required edge right on the same place, think of state compression. And with transitivity, use Floyd. Harvest:a[u][v] |= 1<< (s[i] - 'a '); In the|=is the deposit status.a[i][k] & a[k][j] In the&is to judge there is the same place.
#include <cstdio>#include<iostream>#include<cstdlib>#include<algorithm>#include<ctime>#include<cmath>#include<string>#include<cstring>#include<stack>#include<queue>#include<list>#include<vector>#include<map>#include<Set>using namespacestd;Const intINF =0x3f3f3f3f;Const DoubleEPS = 1e-Ten;Const DoublePI = ACOs (-1.0);Const intMAXN = -;intA[MAXN][MAXN];intMain () {intN; while(~SCANF ("%d", &n) &&N) {intu, v; Memset (A,0,sizeof(a)); while(SCANF ("%d%d", &u, &v) && (u+v)) {Chars[ -]; scanf ("%s", s); for(inti =0; I < strlen (s); i++) A[u][v]|=1<< (S[i]-'a'); } for(intK =1; K <= N; k++) for(inti =1; I <= N; i++) for(intj =1; J <= N; J + +) A[i][j]|= A[i][k] &A[k][j]; while(SCANF ("%d%d", &u, &v) && (u+v)) { for(inti ='a'; I <='Z'; i++) if(A[u][v] & (1<< (I-'a')) printf ("%c", i); if(!A[u][v]) printf ("%c",'-'); Puts (""); } puts (""); } return 0;}
POJ 2579 Fiber Network (state compression +floyd)