Zoj 1221 Risk Shortest Way Floyd

Source: Internet
Author: User
Carefully read the question, found: The edge of the weight value is set to 1, then converted to two points between the shortest path problem ... One excited, with the Dijkstra, and the document ended. =eof forgot to write, TLE ... Then use Floyd, smooth AC ...
#include <stdio.h>
#include <string.h>
int w[21][21];
int main ()
{
 int i,j,t,u,n,ncase=1;
 while (scanf ("%d", &t)!=eof)
 {for  
  (i=1;i<=20;i++)
  {for
    (j=1;j<=20;j++)
      w[i][j]= ; 
    w[i][i]=0;
  }
  for (j=0;j<t;j++)
  {
    scanf ("%d", &u);
    w[1][u]=w[u][1]=1;
  }      
  for (i=2;i<=19;i++)
  {
    scanf ("%d", &t);
    for (j=0;j<t;j++)
    {
      scanf ("%d", &u);
      w[i][u]=w[u][i]=1;
    }
  }
  for (int. k=1;k<=20;k++) for
    (i=1;i<=20;i++) for
      (j=1;j<=20;j++)
        if (W[i][j]>w[i][k]+w[k] [j]) 
          W[I][J]=W[I][K]+W[K][J];
  scanf ("%d", &n);
  printf ("Test Set #%d\n", ncase++);
  for (i=0;i<n;i++)
  {      
    scanf ("%d%d", &t,&u);
    printf ("%d to%d:%d\n", T,u,w[t][u]);
  }
   printf ("\ n");
  }
  return 0;
}


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.