解决报告

思路:

裸裸的最短路。

#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
#define inf 0x3f3f3f3f
#define N 40000
#define M 100000
using namespace std;
struct node
{
int v,w,next;
}edge[M];
int head[N],dis[N],vis[N],cnt,n,m,s,t;
void add(int u,int v,int w)
{
edge[cnt].v=v;
edge[cnt].w=w;
edge[cnt].next=head[u];
head[u]=cnt++;
}
void spfa()
{
for(int i=0;i<n;i++)
{
dis[i]=inf;
vis[i]=0;
}
dis[s]=0;
vis[s]=1;
queue<int >Q;
Q.push(s);
while(!Q.empty()){
int u=Q.front();
Q.pop();
vis[u]=0;
for(int i=head[u];i!=-1;i=edge[i].next)
{
int v=edge[i].v;
if(dis[v]>dis[u]+edge[i].w)
{
dis[v]=dis[u]+edge[i].w;
if(!vis[v])
{
vis[v]=1;
Q.push(v);
}
}
}
}
}
int main()
{
int i,j,T,u,v,w,k=1;
scanf("%d",&T);
while(T--)
{
memset(head,-1,sizeof(head));
cnt=0;
scanf("%d%d%d%d",&n,&m,&s,&t);
for(i=0;i<m;i++)
{
scanf("%d%d%d",&u,&v,&w);
add(u,v,w);
add(v,u,w);
}
spfa();
printf("Case #%d: ",k++);
if(dis[t]==inf)
printf("unreachable\n");
else printf("%d\n",dis[t]);
}
return 0;
}

Problem E

Sending email

Time Limit: 3 seconds

"A new internet watchdog is creating a stir in

Springfield. Mr. X, if that is his real name, has

come up with a sensational scoop."

Kent Brockman

There are n SMTP servers connected by network cables. Each of the m cables connects two computers and has a certain latency measured in milliseconds required to
send an email message. What is the shortest time required to send a message from server S to server T along a sequence of cables?

Assume that there is no delay incurred at any of the servers.

Input

The first line of input gives the number of cases, NN test cases follow. Each one starts with a line containing n(2<=n<20000), m (0<=m<50000), S (0<=S<n)
and T (0<=T<n). S!=T. The next m lines will each contain 3 integers: 2 different servers (in the range [0, n-1]) that are connected by a
bidirectional cable and the latency, w, along this cable (0<=w<=10000).

Output

For each test case, output the line "Case #x:" followed by the number of milliseconds required to send a message from S toT. Print "unreachable" if there is no route from S to T.

Sample Input Sample Output
3
2 1 0 1
0 1 100
3 3 2 0
0 1 100
0 2 200
1 2 50
2 0 0 1
Case #1: 100
Case #2: 150
Case #3: unreachable

Problemsetter: Igor Naverniouk

版权声明:本文博客原创文章。博客,未经同意,不得转载。

UVa10986_Sending email(最短)(白皮书图论的话题)的更多相关文章

  1. UVa-10986_Sending email (向前星+Dijkstra)

    题意:给你点.边,求起点到终点的最短距离. 题解:由于题目的数据量特别大,所以需要用邻接表来存边,之后对Dijkstra算法稍微魔改一下就可以了,本来以为会超时,做好了打堆优化的准备,结果卡时间过了, ...

  2. 训练指南 UVALive - 4080(最短路Dijkstra + 边修改 + 最短路树)

    layout: post title: 训练指南 UVALive - 4080(最短路Dijkstra + 边修改 + 最短路树) author: "luowentaoaa" ca ...

  3. <知识整理>2019清北学堂提高储备D5

    今天主讲图论. 前言:图的定义:图G是一个有序二元组(V,E),其中V称为顶集(Vertices Set),E称为边集(Edges set),E与V不相交.它们亦可写成V(G)和E(G). 一.图的存 ...

  4. SDUT OJ 数据结构实验之图论五:从起始点到目标点的最短步数(BFS)

    数据结构实验之图论五:从起始点到目标点的最短步数(BFS) Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss P ...

  5. 数据结构实验之图论五:从起始点到目标点的最短步数(BFS)

    分析:有向图里面找最短路径,原理就是每一步都走距离自己最近的路, 一旦发现走一步可以到,那么这个一定是最短的. #include <bits/stdc++.h> using namespa ...

  6. [图论]最短网络:prim

    最短网络 目录 最短网络 Description Input Output Sample Input Sample Output 解析 代码 Description 农民约翰被选为他们镇的镇长!他其中 ...

  7. [图论]最短网络:kruskal

    最短网络 目录 最短网络 Description Input Output Sample Input Sample Output 解析 代码 Description 农民约翰被选为他们镇的镇长!他其中 ...

  8. 黑客白皮书:如何成为一名黑客(附FAQ)

    内容一览 为什么会有这份文档? 什么是黑客? 黑客应有的态度 黑客的基本技能 黑客文化中的地位 黑客和书呆子(Nerd)的联系 风格的意义 其它资源 FAQ(常问问题解答)   作为Jargon Fi ...

  9. FBI阅人术——用最短的时间了解一个人

    FBI阅人术--用最短的时间了解一个人 和陌生人第一次见面时,要如何在一开始谈话的几分钟内,了解这个人?如何和对方拉近距离?如何找到对方喜爱的话题?如何让对方愿意开口? 这都得依靠细心而入微的观察力, ...

随机推荐

  1. MVAPI第一个版本架构图

    MVAPI采用矢量与栅格结合的方式进行移动地图的显示. 进过几个月,目前终于可以完成基本的地图显示及操作功能.还有待实现的是各种性能及效果优化.3D地物等. 发一个1.0的架构图留存一下.(虽然目前还 ...

  2. SpringMVC @ResponseBody 415错误处理

    在查看下面部分内容之前,请先检查你的请求蚕食是否正确,如果全部正确,请继续往下看 刚开始用SpringMVC, 页面要使用jQuery的ajax请求Controller. 但总是失败,主要表现为以下两 ...

  3. 使用zTree和json构建简单树节点

    我们经常碰到须要构建树结构展示的情况,我推荐使用zTree和JSON. 比如: <? php /** * * 使用zTree和json构建树节点 * */ $arr = array( 0=> ...

  4. FBReaderJ源代码编译配置

    1.git路径:https://github.com/geometer/FBReaderJ.git 2.project中HowToBuild指引了怎么编译,补充一下: 须要在project文件夹和th ...

  5. oracle11g创建新的用户和改动最大连接数

    create user test identified by root; grant create session,resource to root; alter user test account ...

  6. 运行一个android程序,直接访问某个网站

    package android.com.youtube; import android.app.Activity; import android.content.Intent; import andr ...

  7. UVa 11408 - Count DePrimes

    题目:一个数的素因子的和假设也是素数就叫做DePrimes,统计给定区间内的DePrimes. 分析:数论.本题使用用一种素数的筛法,欧拉筛法,也加线性筛法. 这样的方法,每次删选分两种情况:1.素因 ...

  8. 安装sunvirtualbox

    按照网友提供的方法安装sunvirtualbox,老提示:依赖关系不满足: libpython2.6 (>= 2.6) 后来用终端运行 sudo apt-get install virtualb ...

  9. C# 6.0 (C# vNext) 的新功能:Expression Bodied Functions and Properties

    Expression Bodied Function 它可以用在: methods user-defined operators type conversions read-only properti ...

  10. CSharp SQLServer 登陆

    =======后台SQLServer存储过程================ --创建数据库create database Stu; --创建表use MyShool;if exists(select ...