1005 输出用%f,1009别做了

Problem E

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 96   Accepted Submission(s) : 51
Problem 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 S[sub]Mi[/sub] and L[sub]Mi[/sub], which means that the distance between the i-th town and the S[sub]Mi[/sub] town is L[sub]Mi[/sub].
 
Output
Each case takes one line, print the shortest length that XiaoY reach seaside.
 
Sample Input
5 1 0 1 1 2 0 2 3 3 1 1 1 4 100 0 1 0 1
 
Sample Output
2
 
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define INF 0x3f3f3f3f
using namespace std;
int map[][],dis[];
bool used[];
int sea[];
int n,k,minx;
void init()
{
for(int i=;i<n;i++)
{
for(int j=;j<n;j++)
{
if(i==j) map[i][j] = ;
map[i][j] = INF;
}
}
}
void dijkstral(int s)
{
memset(used,false,sizeof(used));
for(int i=;i<n;i++)
{
dis[i] = map[][i];
} dis[s] = ;
while()
{
int v = -;
for(int u=;u<n;u++)
{
if(!used[u]&&(v==-||dis[u]<dis[v])) v = u;
}
if(v==-) break;
used[v] = true;
for(int u=;u<n;u++)
{
dis[u] = min(dis[u],dis[v]+map[v][u]);
}
}
int minm = INF; for (int i=;i<k;i++)
{
minm = min(minm,dis[sea[i]]);
}
printf ("%d\n",minm);
}
int main()
{
int s,l;
int M,P;
int N;
while(~scanf("%d",&N))
{
int cnt = ;
int y = ;
n = N;
init();
while(N--)
{ scanf("%d%d",&M,&P);
if(P)
{
sea[y++] = cnt;
}
for(int i=;i<M;i++)
{
scanf("%d%d",&s,&l);
map[cnt][s] = min(l,map[cnt][s]);
map[s][cnt] = min(l,map[cnt][s]);
}
cnt++;
}
dijkstral();
}
return ;
}

随机推荐

  1. LoadRunner 事务函数

    status 包括LR_PASS, LR_FAIL,  LR_AUTO,  LR_STOP(这个没用过) lr_set_transaction_instance_status(status); 可以根 ...

  2. Python入门神图

    国外某小哥制作的Python入门神图

  3. 【spring 后台跳转前台】使用ajax访问的后台,后台正常执行,返回数据,但是不能进入前台的ajax回调函数中

    问题: 使用ajax访问的后台,后台正常执行,并且正常返回数据,但是不能进入前台的ajax回调函数中 问题展示:  问题解决: 最后发现是因为后台的方法并未加注解:@ResponseBody,导致方法 ...

  4. 网上下载的CHM帮助文件打不开的解决办法。

    我的机器 装的是 Windows server 2008 操作系统.他的安全性比较高. 我在网上下载了一个 CHM 帮助文档.结果打不开. 现象: 打开时 ,提示 安全警告, 提示:来自Interne ...

  5. Android Fragment学习笔记(二)----Fragment界面添加和管理

    Fragment界面添加 了解过fragment的生命周期等简单知识,于是去看官方文档来了解更多相关内容,要添加fragment到我们的UI界面中,给出了两种常用的方法,第一个是在activity的布 ...

  6. 解读Web Page Diagnostics网页细分图

    解读Web Page Diagnostics网页细分图 http://blog.sina.com.cn/s/blog_62b8fc330100red5.html Web Page Diagnostic ...

  7. NDK各版本下载

    含r8e,r9d,r10c 其中x86_64代表64位系统 官网上只有最新版下载链接,如果想要下载以前的版本,可打开 https://archive.org/web/ 然后输入 http://deve ...

  8. Uva 11988 Broken Keyboard

    因为要经常移动这些字符,所以采用的数据结构是链表. next[i]起到的作用大概就是类似链表里的next指针. 0.需要注意的是,判断cur == last ? 如果 是 则 last=i 1.另外一 ...

  9. no-jquery 01Elements

    Select Elements id // IE 5.5+ document.getElementById('myElement'); // IE 8+ document.querySelector( ...

  10. js中各种宽高

    各种宽高 Javascript: IE中:document.body.clientWidth ==> BODY对象宽度document.body.clientHeight ==> BODY ...