UVA 10896 Sending Email
这个题目真是伤透脑筋了,一直RE,连着改了好几个版本,又是spfa,又是单调队列dijkstra+单调队列,总是不过,后来发现M开小了,双向边应该开m的两倍,悲剧啊!!!以后不管怎样,数组一定要尽量开大点。
折磨的真是痛苦,不过发现了一样好东西,http://uvatoolkit.com/problemssolve.php
uva一个测试工具,输入数据能够给出正确结果,以后不用辛苦到网上找AC代码了,直接输入结果。
#include <cstdio>
#include <cstring>
#include <queue>
#include <cstdlib>
#define N 20010
#define M 100010
#define INF 0x0f0f0f0f using namespace std;
typedef pair<int,int> pii; int next[M],first[M],to[M],w[M];
int d[N],p; void add(int u,int v,int t)
{
to[p] = v;
w[p] = t;
next[p] = first[u];
first[u] = p++;
} int main(void)
{
int T;
for(int t = scanf("%d",&T); t <= T; t++)
{
priority_queue <pii, vector<pii>, greater<pii> > q;
p = ;
memset(first,-,sizeof(first));
int sr,ta,n,m,u,v,c;
scanf("%d%d%d%d",&n,&m,&sr,&ta);
for(int i=;i<m;i++)
{
scanf("%d%d%d",&u,&v,&c);
add(u,v,c);
add(v,u,c);
}
memset(d,0x0f,sizeof(d));
d[sr] = ;
q.push(make_pair(d[sr],sr));
while(!q.empty())
{
pii u = q.top();q.pop();
int x = u.second;
if(u.first != d[x])
continue;
for(int e = first[x]; e != -; e = next[e])
if(d[to[e]] > d[x]+w[e])
{
d[to[e]] = d[x] + w[e];
q.push(make_pair(d[to[e]],to[e]));
}
}
printf("Case #%d: ",t);
if(d[ta]==INF)
puts("unreachable");
else printf("%d\n",d[ta]);
}
return ;
}
UVA 10896 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个SMTP服务器,有m条电缆将它们相连,每条电缆传输信息需要一定的时间.现在给出信息的起点和终点,计算所需的最小时间. 有权图上的单源最短路问题(Single-Source Sho ...
- UVA 10986 Sending email 最短路问题
基本的最短路问题 就是数据需要稍微处理一下.(N比较大)dijkstra也要优化.不优化应该会T: #include <map> #include <set> #include ...
- Sending e-mail with Spring MVC---reference
reference from:http://www.codejava.net/frameworks/spring/sending-e-mail-with-spring-mvc Table of con ...
- 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. ...
- Sending Email In .NET Core 2.0
Consider the following written in .NET Core 2.0. SmtpClient client = ) { UseDefaultCredentials = tru ...
随机推荐
- 月半小夜曲下的畅想--DOCTYPE模式
月半小夜曲下的畅想--DOCTYPE模式 @(css3 box-sizing)[doctype声明|quirks模式|妙瞳] DOCTYPE文档类型标签,该标签是将特定的标准通用标记语言或者XML文档 ...
- 命令行创建AVD
1.命令行创建AVD android create avd -n myAvd -t 8 -b armeabi-v7a -p d:\scard.img -s HVGA 2.删除AVD android d ...
- 批量杀进程——xargs用途
ps -ef|grep ora|grep “LOCAL=YES”|awk ‘{print $2}’|xargs –I {} kill -9 {} ps -ef|grep ora|grep “LOCAL ...
- Jquery 1.11.1 Checkbox checked 判断
if($(this).prop('checked'))
- 11_Servlet生命周期
[生命周期] 以前:之前的java程序,我们的Java类自己去new对象,自已实例化对象去调用. 现在:Servlet程序,Servlet的生命周期由TomCat服务器控制的. 我们要研究Servle ...
- vmware以及schlumberger题解
先是vmare的:具体的题目我就不描述了. 1. 贪吃的小明.直接数个数,统计个数,就可以完成.使用map,应该输入implement这一类,我认为很简单,但是我只过了33%. /* ID: y119 ...
- From MSI to WiX, Part 2 - ARP support, by Alex Shevchuk
Following content is directly reprinted from From MSI to WiX, Part 2 - ARP support Author: Alex Shev ...
- LevelDb原理剖析
在说LevelDb之前,先认识两位大牛,Jeff Dean和Sanjay Ghemawat,这两位是Google公司重量级的工程师,为数甚少的Google Fellow之二. Jeff Dean其人: ...
- HTML5之 离线数据存储
--- Storage接口 无论是sessionStorage还是localStorage 属性/方法 返回值 描述 ----------------------------------------- ...
- 微信公众号-5秒内不回复测试并处理方案,顺便复习php 时间执行
在index.php中 file_put_contents('has_request.txt','请求时间:'.date('YmdHis')."\n",FILE_APPEND); ...