题目大意:网络中有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的更多相关文章

  1. uva 10986 - Sending email(最短路Dijkstra)

    题目连接:10986 - Sending email 题目大意:给出n,m,s,t,n表示有n个点,m表示有m条边,然后给出m行数据表示m条边,每条边的数据有连接两点的序号以及该边的权值,问说从点s到 ...

  2. UVA 10986 Sending email 最短路问题

    基本的最短路问题 就是数据需要稍微处理一下.(N比较大)dijkstra也要优化.不优化应该会T: #include <map> #include <set> #include ...

  3. UVA 10896 Sending Email

    这个题目真是伤透脑筋了,一直RE,连着改了好几个版本,又是spfa,又是单调队列dijkstra+单调队列,总是不过,后来发现M开小了,双向边应该开m的两倍,悲剧啊!!!以后不管怎样,数组一定要尽量开 ...

  4. Sending e-mail with Spring MVC---reference

    reference from:http://www.codejava.net/frameworks/spring/sending-e-mail-with-spring-mvc Table of con ...

  5. UVA.10986 Fractions Again (经典暴力)

    UVA.10986 Fractions Again (经典暴力) 题意分析 同样只枚举1个,根据条件算出另外一个. 代码总览 #include <iostream> #include &l ...

  6. Sending e-mail with Spring MVC--转载

    原文地址:http://www.codejava.net/frameworks/spring/sending-e-mail-with-spring-mvc Table of contents: 1.S ...

  7. 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 ...

  8. Spring – Sending E-Mail Via Gmail SMTP Server With MailSender--reference

    Spring comes with a useful ‘org.springframework.mail.javamail.JavaMailSenderImpl‘ class to simplify ...

  9. Sending e-mail

    E-mail functionality uses the Apache Commons Email library under the hood. You can use theplay.libs. ...

随机推荐

  1. PAT (Advanced Level) 1095. Cars on Campus (30)

    模拟题.仔细一些即可. #include<cstdio> #include<cstring> #include<cmath> #include<algorit ...

  2. Windows 2003】利用域&&组策略自动部署软件

    Windows 2003]利用域&&组策略自动部署软件 转自 http://hi.baidu.com/qu6zhi/item/4c0fa100dc768613cc34ead0 ==== ...

  3. HBase的Shell命令

    1.HBase提供了一个shell的终端给用户交互 2.HBase Shell的DDL操作 (1)先进入HBase的 Shell命令行,即HBASE_HOME/bin/hbase shell …… & ...

  4. struts2整合spring应用实例

    我们知道struts1与spring整合是靠org.springframework.web.struts.DelegatingActionProxy来实现的,以下通过具体一个用户登录实现来说明stru ...

  5. CentOS 6.5 开机启动指定服务

    gedit /etc/rc.d/rc.local #关闭防火墙 service iptables stop #开启samba服务 service smb start #开启ntopng 端口5000 ...

  6. JAVA实现二进制,十六进制输出

    public class Main { /** * @param args */ public static void main(String[] args) { // TODO Auto-gener ...

  7. 国内apk加固的破解方法

    国内apk加固的破解方法 By Bob Pan 国内的apk加固技术都使用了将原有的dex隐藏, 在运行时解压, 并且通过修改app的类加载器的方式实现加固. 参考: AndoridAPK反逆向解决方 ...

  8. Python的import嵌套

    [root@fuel ~]# vi /var/lib/docker/devicemapper/mnt/4da57a0078c9d3f32e819373b67de41da37c34a27ee03f740 ...

  9. Monkey and Banana(基础DP)

    Monkey and Banana Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  10. PAT (Advanced Level) 1029. Median (25)

    scanf读入居然会超时...用了一下输入挂才AC... #include<cstdio> #include<cstring> #include<cmath> #i ...