Zoj (1221

Source: Internet
Author: User

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1221

The first 19 lines of the problem give a link to the city's connectivity, such as

1 3
2 3 4
3 4 5 6
1 6
1 7
2 12 13
1 8
2 9 10
1 11
1 11
2 12 17
1 14
2 14 15
2 15 16
1 16
1 19
2 18 19
1 20
1 20
5
1 20
2 9
19 5
18 19
16 20

The first line indicates that the first city has 1 cities connected to it, and that the city is 3, then N, asking for the shortest path of u->v = =.

Given that the data is only 20 cities, use the Freud shortest

#include <stdio.h>#include<string.h>#include<iostream>#include<algorithm>using namespacestd;intf[ -][ -];#defineINF 9999999intMain () {intn,m; intCnt=0;  while(SCANF ("%d", &n)! =EOF) {         for(intI=0; i<= A; i++)        {             for(intj=0; j<= A; j + +) F[i][j]=inf; }         for(intI=0; i<n;i++) {scanf ("%d",&m); f[1][m]=1; f[m][1]=1; }         for(intI=2; i<= +; i++) {scanf ("%d",&N);  for(intj=0; j<n;j++) {scanf ("%d",&m); F[I][M]=1; F[m][i]=1; }        }                 intt,ans=0, U,v;  for(intk=1; k<= -; k++)            {                 for(intI=1; i<= -; i++)                {                     for(intj=1; j<= -; j + +)                    if(f[i][k]+f[k][j]<F[i][j]) f[i][j]=f[i][k]+F[k][j]; }} scanf ("%d",&t); printf ("Test Set #%d\n",++CNT);  while(t--) {scanf ("%d%d",&u,&v); printf ("%d to%d:%d\n", U,v,f[u][v]); } printf ("\ n"); }    return 0;}

Zoj (1221

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.