UVA 10986 Sending email 最短路问题
基本的最短路问题 就是数据需要稍微处理一下。(N比较大)dijkstra也要优化。不优化应该会T;
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define PI 3.1415926535897932626
using namespace std;
int gcd(int a, int b) {return a % b == ? b : gcd(b, a % b);}
int N,M,S,T;
const int INF = 0x3f3f3f3f;
typedef pair<int,int> pii;
#define MAXN 20005
priority_queue<pii,vector<pii>,greater<pii> >q;
struct node
{
int v;
int w;
};
vector <node>G[MAXN];//G[u].v = w present dis[u][v] = w;
int d[MAXN];
void read()
{
scanf("%d%d%d%d",&N,&M,&S,&T);
for (int i = ; i <= N; i++)G[i].clear();
while (M--)
{
int u,v,w;
scanf("%d%d%d",&u,&v,&w);
node tmp; tmp.v = v; tmp.w = w;
G[u].push_back(tmp);
tmp.v = u; tmp.w = w;
G[v].push_back(tmp);
}
}
void dijkstra(int st)
{
memset(d,0x3f,sizeof(d));
d[st] = ;
// printf("%d\n",st);
while (!q.empty()) q.pop();
q.push(make_pair(d[st],st));
while (!q.empty())
{
pii u = q.top(); q.pop();
int x = u.second;
if (u.first != d[x]) continue;
for (int i = ; i < (int)G[x].size(); i++)
{
int v = G[x][i].v, w = G[x][i].w;
//printf("%d %d\n",v,w);
if (d[v] > d[x] + w)
{
d[v] = d[x] + w;
//printf("%d %d\n",d[v],v);
q.push(make_pair(d[v],v));
}
}
}
}
int main()
{
int num, kase = ;
scanf("%d",&num);
while (num--)
{
read();
dijkstra(S);
if (d[T] == INF) printf("Case #%d: unreachable\n",kase++);
else printf("Case #%d: %d\n",kase++,d[T]);
}
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个SMTP服务器,有m条电缆将它们相连,每条电缆传输信息需要一定的时间.现在给出信息的起点和终点,计算所需的最小时间. 有权图上的单源最短路问题(Single-Source Sho ...
- 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. ...
随机推荐
- POJ:3061-Subsequence(尺取法模板详解)
Subsequence Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 18795 Accepted: 8043 Descript ...
- BurpSuite 的使用
最好用的抓包软件, 不只是抓包软件 IE/Chrome中设置代理的方法是, 打开Internet选项面板->连接->局域网设置->取消勾选的使用自动配置脚本->勾选为LAN使用 ...
- Maven系列之快速入门
文章结构 唯快不破---Maven快速入门 稳打稳扎---Maven核心知识 实用为先---Maven如何建立Web项目 1 唯快不破---Maven快速入门 1.1 Maven项目 ...
- 4,Flask 中的 request
每个框架中都有处理请求的机制(request),但是每个框架的处理方式和机制是不同的 为了了解Flask的request中都有什么东西,首先我们要写一个前后端的交互 基于HTML + Flask 写一 ...
- linux压缩和解压缩命令大全--费元星站长
tar命令 解包:tar zxvf FileName.tar 打包:tar czvf FileName.tar DirName gz命令 解压1:gunzip FileName.gz 解压2:gzip ...
- Fiddler - 使用教程
1.断点调试,修改请求表单和响应数据 命令介绍: bpu在请求开始时中断,bpafter在响应到达时中断,bps在特定http状态码时中断,bpv/bpm在特定请求method时中断. bpu m.t ...
- 如何使用malloc申请一个二位数组
fscanf(file, "%d", &iVertexNum); // Read number of Vertices double **G = (double **)ma ...
- 手把手教你写Windows 64位平台调试器
本文网页排版有些差,已上传了doc,可以下载阅读.本文中的所有代码已打包,下载地址在此. ------------------------------------------------------- ...
- Python面试题之一:解密
Python面试题之一: 说明:就是Python工程师面试题 一.字典转换与正则提取值 1:key与Value交换 a = {'a':1,'b':2} print({value:key for key ...
- iterm2+vim使用
iterm2+vim 终端切换为iterm2+zsh+oh my zsh,确实好用. I term2常用快捷键记录 新建标签:cmd+t 关闭标签:cmd+w 切换标签:cmd+数字, 切换全屏:cm ...