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 ...
随机推荐
- JAXB - XML Schema Types, Binary Data
Data that has no "natural" representation with printable characters must, for inclusion in ...
- JAXB - Validate Document before It is Unmarshalled
Validation A considerable part of the XML Schema language deals with facets, enabling the programmer ...
- jquery扩展 $.fn
$.fn是指jquery的命名空间,加上fn上的方法及属性,会对jquery实例每一个有效. 如扩展$.fn.abc(),即$.fn.abc()是对jquery扩展了一个abc方法,那么后面你的每一个 ...
- Dojo Tree设置默认选中项并且获得它
先上用来生成Tree的JSON数据 [ { "id": "Root", "name": "资源目录" }, ...
- HW--漂亮度
描述 给出一个名字,该名字有26个字符串组成,定义这个字符串的“漂亮度”是其所有字母“漂亮度”的总和.每个字母都有一个“漂亮度”,范围在1到26之间.没有任何两个字母拥有相同的“漂亮度”.字母忽略大小 ...
- Web前端开发:SQL Jsp小项目(二)------添加修改
沿着昨天整理好的页面,今天实现list页面中的修改, User update框架 需要的效果图: 先看用户查询界面, 修改id为4的那个用户: 修改后返回用户查看界面. 1 .先是从list界面开始, ...
- InstallShield 版本转换
InstallShield : 如何用低版本 打开高版本的工程 InstallShield 每个版本都有对应的版本号SchemaVersion,如下所示 InstallShield Versi ...
- Headfirst设计模式的C++实现——适配器(Adapter)
duck.h #ifndef _DUCK_H_ #define _DUCK_H_ class DUCK { public: ; ; }; #endif mallard_duck.h #ifndef _ ...
- Cloudcraft: 云架构图形可视化(智能AWS图表)
Cloudcraft: 云架构图形可视化(智能AWS图表) 2016.09.11 官方网站: https://cloudcraft.co/ Cloudcraft是一个Web应用,用图形表示各种AWS服 ...
- git 使用事项
基本安装可查看 http://help.github.com 如果删除了本地的文件,要恢复相关文件,在github存在(别人增加的),则:git pull <远程主机名> <远程分支 ...