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. ...
随机推荐
- mysql分页pagination
http://www.phpjabbers.com/php--mysql-select-data-and-split-on-pages-php25.html returns 20 records so ...
- iOS之tabbar图片去除渲染以及字体颜色统一配置
转发:http://www.cnblogs.com/qianLL/p/5521228.html 方式一 代码实现 这种要写很多代码 ,每个控制器都要写 UIImage *image=[UII ...
- zf-安徽桐城关于(资源中心-数据录入)上传文件后没有进行处理Excel文件的原因
上传的文件 是会自动复制到另外一个路径的 如果没有进行处理 那么表示那个路径并没有那个文件 这样就会卡死 导致之后的文件都不会进行处理(后台有个变量是从数据库里获得文件路径的),所以需要去数据库 执行 ...
- zf-关于注册码过期
Webroot-index.jsp下 少写了个函数 导致登陆进去不能弹出注册码过期的对话框,函数如下 window.onload = function() { <ww:iterator valu ...
- 转 SQL 基础--> NEW_VALUE 的使用
--=============================== -- SQL 基础--> NEW_VALUE 的使用 --=============================== 通常 ...
- webView进度条
self.progress = [[NJKWebViewProgress alloc] init]; self.webView.delegate = self.progress; __weak typ ...
- ida调试 android so
C:\Documents and Settings\Administrator>adb shellshell@htc_v2_dtg:/ $ susushell@htc_v2_dtg:/ # cd ...
- (转)Vim的Python编辑器详细配置过程 (Based on Ubuntu 12.04 LTS)
为什么要用vim编辑py文件? 因为在Linux命令行中,缺少图形界面的IDE,vim是最佳的文本编辑器,而为了更好的编辑py文本,所以配置vim. 1. 安装完整版vim vi和vim的区别? 在L ...
- 使用Three.js渲染Sketchup导出的dae
打算做个轮盘游戏,直接上3D吧. 第一步:制作模型 3DMax和Maya下载和破解比较麻烦, 就用之前的Sketchup来试试吧. 最后效果图: 俯视图 仰视图 制作步骤: 1 先画一个圆 2 从圆心 ...
- js正则表达式大全(转)
1. 正则表达式规则 1.1 普通字符 字母.数字.汉字.下划线.以及后边章节中没有特殊定义的标点符号,都是"普通字符".表达式中的普通字符,在匹配一个字符串的时候,匹配与之相同的 ...