基本的最短路问题 就是数据需要稍微处理一下。(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 最短路问题的更多相关文章

  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个SMTP服务器,有m条电缆将它们相连,每条电缆传输信息需要一定的时间.现在给出信息的起点和终点,计算所需的最小时间. 有权图上的单源最短路问题(Single-Source Sho ...

  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. 第二章习题 C++

    1.编写一个程序,显示您的姓名和地址. #include<iostream> using namespace std; int main() { ]; cout << &quo ...

  2. poj 1957 二分搜索

    题意:N个灯泡离地H_i,满足H1 = A ,Hi = (Hi-1 + Hi+1)/2 – 1,HN = B ,求最小B. 思路: 只要二分第二个灯泡的高度就可以推出全部灯泡的高度 如果hi<0 ...

  3. Json的用处一

    今天,我们用到了json的的用处,其实也就是一个很简单的用处,就是点击一个按钮,触发一个事件,然后调用json, 之后我们就可以进行异步操作,其实只是针对于后台的操作,其实我们并没有对数据库进行刷新, ...

  4. Go实现try-catch-finally机制

    前言 许多主流语言诸如:Java.Python都实现了try-catch-finally机制,而Go处理错误的方式却与前两种语言不同.关于Go处理异常的方式是好是坏仁者见仁智者见智,笔者还是更喜欢tr ...

  5. 【tomacat集群】Linux或 window配置多个Tomcat同时运行-完美解决-未来星开发团队-费元星

    Linux系统下怎样配置多个Tomcat同时运行呢,首先修改变量为第一个tomcat,然后修改第二个tomcat启动的脚本 如何在同一系统里同时启动多个Tomcat    http://www.cnb ...

  6. Django笔记 —— 入门简介

    最近在学习Django,打算玩玩网页后台方面的东西,因为一直很好奇但却没怎么接触过.Django对我来说是一个全新的内容,思路想来也是全新的,或许并不能写得很明白,所以大家就凑合着看吧- 本篇笔记(其 ...

  7. 【Max Points on a Line 】cpp

    题目: Given n points on a 2D plane, find the maximum number of points that lie on the same straight li ...

  8. Python 模块:random 随机数生成

    Python中的random模块用于生成随机数. 使用该模块之前需要 import random 几个常用的函数用法: 1.random.random 函数原型: random.random() 用于 ...

  9. 自动化测试(三)如何用python写一个函数,这个函数的功能是,传入一个数字,产生N条邮箱,产生的邮箱不能重复。

    写一个函数,这个函数的功能是,传入一个数字,产生N条邮箱,产生的邮箱不能重复.邮箱前面的长度是6-12之间,产生的邮箱必须包含大写字母.小写字母.数字和特殊字符 和上一期一样 代码中间有段比较混沌 有 ...

  10. 【非原创】tomcat 安装时出现 Failed to install Tomcat7 service

    tomcat 安装时出现 Failed to install Tomcat7 service 今天在安装tomcat时提示 Failed to install Tomcat7 service了,花了大 ...