POJ 2570 Fiber Network

Source: Internet
Author: User
Tags cmath

The shortest-circuit distortion.


Test instructions is to say that different points have different companies that have different connections established.


Ask A, b if there is a pathway, there are those companies.


I use a bool g[][][26] to represent 26 letters. Then Floyd, g++ time out. C + + is AC.


And then look at someone else's code to know there's a bit operation ... ORZ ...


Own code: C + + AC. 813ms

#include <cstdio> #include <cstring> #include <string> #include <queue> #include <algorithm > #include <map> #include <stack> #include <iostream> #include <list> #include <set># Include<cmath> #define INF 0x7fffffff#define EPS 1e-6#define LL long longusing namespace Std;bool g[201][201][26]; int n;void Flyod () {for (int. k=1;k<=n;k++) {for (int. i=1;i<=n;i++) {for (int j=1;j< =n;j++) {for (int l=0;l<26;l++) {if (g[i][k][l]&&g[                K][J][L]) g[i][j][l]=1;        }}}}}int main () {while (scanf ("%d", &n), n) {int u,v;        Char tmp[26];        for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) memset (g[i][j],0,sizeof (G[i][j]));            while (scanf ("%d%d", &u,&v)) {if (u==0&&v==0) break;            scanf ("%s", TMP); Forint i=0;tmp[i]!= ' + '; i++) {g[u][v][tmp[i]-' a ']=1;        }} flyod ();            while (scanf ("%d%d", &u,&v)) {if (u==0&&v==0) break;            BOOL flag=0; for (int k=0;k<26;k++) {if (G[u][v][k]) {printf ("%c", K + ' a ')                    ;                flag=1;            }} if (!flag) puts ("-");        Else puts ("");    } puts (""); }}


Code for bit operation following write: g++ 63ms

#include <cstdio> #include <cstring> #include <string> #include <queue> #include <algorithm > #include <map> #include <stack> #include <iostream> #include <list> #include <set># Include<cmath> #define INF 0x7fffffff#define EPS 1e-6#define LL long longusing namespace Std;int m[201][201];int n;i    NT main () {int A, B;    Char str[27];    Char ch;        while (scanf ("%d", &n) && N) {memset (m, 0, sizeof (m));            while (scanf ("%d%d", &a, &b)) {if (A = = 0 && B = = 0) break;            scanf ("%s", str);            for (int i=0; str[i]; i++) {m[a][b] |= 1 << (str[i]-' A ');        }} int i,j,k;                 For (k=1, k<=n; k++) {for (I=1, i<=n; i++) {for (j=1; j<=n; j + +)                {M[i][j] |= M[i][k] & M[k][j];    }            }        }    while (scanf ("%d%d", &a, &b)) {if (A = = 0 && B = = 0) break; For (ch= ' a '; ch<= ' z '; ch++) {if (M[a][b] & (1 << ch-' a ')) put            char (CH);            } if (!m[a][b]) Putchar ('-');        Puts ("");    } puts (""); } return 0;}



POJ 2570 Fiber Network

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.