HDU 3665 Seaside
来源:互联网 发布:矩阵和伴随矩阵的秩 编辑:程序博客网 时间:2024/05/20 17:27
Seaside
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
XiaoY is living in a big city, there are N towns in it and some towns near the sea. All these towns are numbered from 0 to N-1 and XiaoY lives in the town numbered ’0’. There are some directed roads connecting them. It is guaranteed that you can reach any town from the town numbered ’0’, but not all towns connect to each other by roads directly, and there is no ring in this city. One day, XiaoY want to go to the seaside, he asks you to help him find out the shortest way.
Input
There are several test cases. In each cases the first line contains an integer N (0<=N<=10), indicating the number of the towns. Then followed N blocks of data, in block-i there are two integers, Mi (0<=Mi<=N-1) and Pi, then Mi lines followed. Mi means there are Mi roads beginning with the i-th town. Pi indicates whether the i-th town is near to the sea, Pi=0 means No, Pi=1 means Yes. In next Mi lines, each line contains two integers SMi and L Mi, which means that the distance between the i-th town and the SMi town is L Mi.
Output
Each case takes one line, print the shortest length that XiaoY reach seaside.
Sample Input
51 01 12 02 33 11 14 1000 10 1
Sample Output
2#include<stdio.h>#include<string.h>#define INF 0x3f3f3f#include<algorithm>using namespace std;int map[15][15];int dis[15];int n;int floyd(){for(int k=1;k<n;k++)for(int i=0;i<n;i++)for(int j=0;j<n;j++){if(map[i][j]>map[i][k]+map[k][j])map[i][j]=map[i][k]+map[k][j];}}int main(){int a,b,c,d,res;while(~scanf("%d",&n)){for(int i=0;i<n;i++){for(int j=0;j<n;j++)map[i][j]=INF;map[i][i]=0;}memset(dis,0,sizeof(dis));res=INF;for(int i=0;i<n;i++){scanf("%d%d",&a,&b);dis[i]=b;for(int j=0;j<a;j++){scanf("%d%d",&c,&d);map[i][c]=d;}}floyd();for(int i=0;i<n;i++){if(dis[i] && map[0][i]<res)res=map[0][i];}printf("%d\n",res);}}
0 0
- hdu 3665 Seaside
- hdu 3665:Seaside
- hdu 3665 Seaside
- HDU--3665--Seaside
- Seaside HDU 3665 【Dijkstra】
- hdu-3665 Seaside
- HDU 3665 Seaside
- hdu 3665 seaside floyd
- HDU-3665-Seaside
- HDU-3665 Seaside
- HDU 3665 Seaside 最短路
- hdu 3665Seaside(简单floyd)
- HDU 3665 Seaside(简单Floyd)
- HDU -- 3665 Seaside (Floyd)
- hdu 3665 Seaside(最短路)
- HDU 3665 Seaside <迪杰斯特拉算法>
- hdu 3665 Seaside 最短路
- hdu 3665 Seaside【裸最短路】
- React Native开发安装和创建工程
- Java 8: 从永久代(PermGen)到元空间(Metaspace)
- oracle常用函数
- FB 硬件抽象层gralloc原理流程分析
- 【大话数据结构&算法】希尔排序(Java/C实现源码)
- HDU 3665 Seaside
- 二叉树中两个节点的最近公共祖先节点
- hdu5793 A Boring Question(推公式or迷之找规律)
- PhpStorm无法使用Terminal解决方法
- Maven那点事儿(Eclipse版)
- ue4 中动画控制,利用conduit节点
- JAVA学习笔记----接口、抽象类、内部类
- 【CDP-云设计模式】第6章,3.直接对象上传模式(Direct Object Upload Pattern)
- 根据前序遍历序列和中序遍历序列构造二叉树算法