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. ...
随机推荐
- DIV 浮动存不占空间
DIV 浮动存不占空间比如<div style="width:80px; border:1px solid #333"><div style="floa ...
- java网络之tcp
简单tcp传输 package pack; /* 演示tcp传输. 1,tcp分客户端和服务端. 2,客户端对应的对象是Socket. 服务端对应的对象是ServerSocket. 客户端, 通过查阅 ...
- java数据类型,hibernate数据类型,标准sql数据类型之间的对应表
Hibernate API简介 其接口分为以下几类: l 提供访问数据库的操作的接口: l 用于配置Hibernate的接口: l 回调接口 l ...
- Android-----View绘制流程以及invalidate()等相关方法分析 .
引自:http://blog.csdn.net/qinjuning/article/details/7110211 前言: 本文是我读<Android内核剖析>第13章----View工作 ...
- .OpenWrt驱动程序Makefile的分析概述 、驱动程序代码参考、以及测试程序代码参考
# # # include $(TOPDIR)/rules.mk //一般在 Makefile 的开头 include $(INCLUDE_DIR)/kernel.mk // 文件对于 软件包为内核时 ...
- jdbc批量执行SQL insert 操作
package com.file; import java.io.BufferedReader; import java.io.FileReader; import java.util.ArrayLi ...
- PAT (Advanced Level) 1060. Are They Equal (25)
模拟题.坑点较多. #include<iostream> #include<cstring> #include<cmath> #include<algorit ...
- 如何把一个TXT文本文件按行数分割成多个文本文件
2011-04-27 12:00:24| 分类: 默认分类 |字号 订阅 网上有很多文本分割软件都是按字节大小来分割的,主要用于小说类的文本分割,对于比较有规则的内容按行数进行分割非常不方便 ...
- html精确定位
1.offsetwidth.offsetHeight是指包含border的元素宽高. 2.clientWidth.clientHeight是指不包含border的元素宽高. 3.scrollWidth ...
- Sping--AOP--XML
IoC: annotation AOP: XML XML比annotation用的多. beans.xml: <?xml version="1.0" encoding=&qu ...