UVa 10986 - Sending email
题目大意:网络中有n个SMTP服务器,有m条电缆将它们相连,每条电缆传输信息需要一定的时间。现在给出信息的起点和终点,计算所需的最小时间。
有权图上的单源最短路问题(Single-Source Shortest Path, SSSP),直接使用Dijkstra算法。
#include <cstdio>
#include <vector>
#include <queue>
using namespace std;
typedef pair<int, int> ii;
typedef vector<ii> vii;
#define INF 1e9
#define TRvii(c, it) \
for (vii::iterator it = (c).begin(); it != (c).end(); it++) int main()
{
#ifdef LOCAL
freopen("in", "r", stdin);
#endif
int T;
scanf("%d", &T);
for (int kase = ; kase <= T; kase++)
{
int n, m, s, t;
scanf("%d%d%d%d", &n, &m, &s, &t);
vector<vii> AdjList(n);
for (int i = ; i < m; i++)
{
int u, v, weight;
scanf("%d%d%d", &u, &v, &weight);
AdjList[u].push_back(ii(v, weight));
AdjList[v].push_back(ii(u, weight));
}
vector<int> dist(n, INF);
dist[s] = ;
priority_queue<ii, vector<ii>, greater<ii> > pq;
pq.push(ii(, s));
while (!pq.empty())
{
ii top = pq.top();
pq.pop();
int d = top.first, u = top.second;
if (d == dist[u])
TRvii(AdjList[u], it)
{
int v = it->first, weight = it->second;
if (dist[u] + weight < dist[v])
{
dist[v] = dist[u] + weight;
pq.push(ii(dist[v], v));
}
}
}
if (dist[t] != INF) printf("Case #%d: %d\n", kase, dist[t]);
else printf("Case #%d: unreachable\n", kase);
}
return ;
}
UVa 10986 - Sending email的更多相关文章
- uva 10986 - Sending email(最短路Dijkstra)
题目连接:10986 - Sending email 题目大意:给出n,m,s,t,n表示有n个点,m表示有m条边,然后给出m行数据表示m条边,每条边的数据有连接两点的序号以及该边的权值,问说从点s到 ...
- UVA 10986 Sending email 最短路问题
基本的最短路问题 就是数据需要稍微处理一下.(N比较大)dijkstra也要优化.不优化应该会T: #include <map> #include <set> #include ...
- UVA 10896 Sending Email
这个题目真是伤透脑筋了,一直RE,连着改了好几个版本,又是spfa,又是单调队列dijkstra+单调队列,总是不过,后来发现M开小了,双向边应该开m的两倍,悲剧啊!!!以后不管怎样,数组一定要尽量开 ...
- Sending e-mail with Spring MVC---reference
reference from:http://www.codejava.net/frameworks/spring/sending-e-mail-with-spring-mvc Table of con ...
- UVA.10986 Fractions Again (经典暴力)
UVA.10986 Fractions Again (经典暴力) 题意分析 同样只枚举1个,根据条件算出另外一个. 代码总览 #include <iostream> #include &l ...
- Sending e-mail with Spring MVC--转载
原文地址:http://www.codejava.net/frameworks/spring/sending-e-mail-with-spring-mvc Table of contents: 1.S ...
- Sending Email from mailx Command in Linux Using Gmail’s SMTP
The mailx or mail command in Linux is still providing service for guys like me, especially when we n ...
- Spring – Sending E-Mail Via Gmail SMTP Server With MailSender--reference
Spring comes with a useful ‘org.springframework.mail.javamail.JavaMailSenderImpl‘ class to simplify ...
- Sending e-mail
E-mail functionality uses the Apache Commons Email library under the hood. You can use theplay.libs. ...
随机推荐
- c++ data语意学
Data Member的绑定 extern float x; class Point3d { public: point3d(); //问题:被传回和被设定的x是哪一个x呢? float X() c ...
- Talking about Health
George: Doctor, what is the best way to stay healthy? Dictor: Having a good diet is probably the mos ...
- PAT1015
A reversible prime in any number system is a prime whose "reverse" in that number system i ...
- GPRS的工作原理、主要特点
源:http://blog.csdn.net/sdudubing/article/details/7682467 GPRS的工作原理.主要特点: 引 言 近年来,通信技术和网络技术的迅速发展,特别是无 ...
- Kali-linux安装之后的简单设置(转)
1.更新软件源: 先备份软件源文件 cp /etc/apt/sources.list /etc/apt/sources.list.bak 修改sources.list文件: leafpad /etc/ ...
- make[1]: *** [/workopenwrt/trunk/staging_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/stamp/.tools_install_nnnnn] Error 2 make[1]: Leaving directory `/work/openwrt/trunk' make: *** [world]
主要原因是编译时未连上网,编译时需要下载些插件,连接网后,重启下系统再编译下.
- 对于crontab定时任务不能自动执行的总结
最近遇到了一些sh不能在crontab定时任务中自动执行的问题 期间由于不太了解,故走了一点弯路,现在总结下来可能第一次 进行设置遇到的问题.以绝后患!我所用过的操作系统为HP-unix&li ...
- C# devExpress GridControl 行中行 子行 多级行
在工作中经常会碰到需要做行中行,多级行的情况,不熟的情况下,我也只能试着实现. 命名空间 using DevExpress.XtraEditors.Repository; using System.D ...
- decoder3_8
这两天回归书本,继续阅读书上的内容,此时的体会与刚开始学那会的体会是不一样的,比如3_8decoder,之前就认为可以用case来写,而书上有一种更简便的方式来描述,带给你新的思路,既然有新方式可以描 ...
- jQuery HighchartsTableHTML表格转Highcharts图表插件
版权申明jQuery HighchartsTable 由 PMSIpilot 创建,中文使用文档由Highcharts中文网发布本文由Theo.红烧鸡翅膀.Mr.Zhang 翻译整理,版权归Highc ...