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. ...
随机推荐
- G - Dreamoon and NightMarket Gym - 101234G 优先队列+思路
题目:题目链接 题意:给出n种食物,食物有自己的价格并且可以自由搭配,每天吃之前没吃过的花费最少的搭配,问第k天的花费. 思路:第k小我们考虑用优先队列处理,虽然n比较大,但由于1 ≤ K ≤ min ...
- Mplab X IDE 安装DMCI
DMCI在Mplab 8中是默认安装的,在 Mplab X IDE中是作为插件,默认不安装. 找到 勾选前面的复选框,点击安装
- spark stream简介
1.复杂的迭代计算 假如我们计算的需要100步的计算,但是当我执行到第99步的时候,突然数据消失, 根据血统,从头进行恢复,代价很高 sc.setCheckpointDir("共享存储文件系 ...
- 4,Flask 中的 request
每个框架中都有处理请求的机制(request),但是每个框架的处理方式和机制是不同的 为了了解Flask的request中都有什么东西,首先我们要写一个前后端的交互 基于HTML + Flask 写一 ...
- viewpager 无网络的时候滑动异常
不知道大家有没有遇到过这种情况,就是框架是viewpager+fragment的架构.然后呢,fragment里面是webview.一般情况下,当没有网的时候,webviwe会说什么找不到网页,然后很 ...
- Spring 各种注解备注
Spring 各种注解备注 felix_feng 关注 2016.12.28 10:34* 字数 2092 阅读 790评论 0喜欢 6 转载 (http://blog.csdn.net/sudilu ...
- 后端接口迁移(从 webapi 到 openapi)前端经验总结
此文已由作者张磊授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 前情提要 以前用的是 webapi 现在统一切成 openapi,字段结构统统都变了 接入接口 20+,涉及模 ...
- 用scrapy数据抓取实践
本文来自网易云社区 作者:沈高峰 数据分析中需要用到的不少数据都是需要进行抓取的,并且需要对抓取的数据进行解析之后存入数据库.scrapy是一个强大的爬虫框架,本文简单介绍下使用scrapy进行垂直抓 ...
- 【HTML&CSS】 第一章:DTD文档声明
<!DOCTYPE> 声明必须是 HTML 文档的第一行,位于 <html> 标签之前. <!DOCTYPE> 声明不是 HTML 标签:它是指示 web 浏览器关 ...
- 发送广播重新挂载SD卡,使图库可以及时显示自己保存的图片(无需手机重启)
我们或许经常会遇到这种情况,明明保存了图片,但是当你打开图片时,却没有找到这张图片,手机重启之后才能看到.这是因为SD卡并没有重新挂载,图库也无法把这张图片加载进去,解决这个问题非常简单,只需要我们模 ...