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. ...
随机推荐
- 用python实现【五猴分桃】问题
转载链接:https://blog.csdn.net/cy309173854/article/details/78296839 据说“五猴分桃”问题最先是由大物理学家狄拉克提出来的,这一貌似简单的问题 ...
- python-9-IO编程
1-文件读写 f = open('d:/file.txt','r') #如果文件不存在会报异常 print(f.read()) #一次性读取所有内容 f.close() 1.2 由于文件操作会用异常, ...
- Linux与BSD不同
https://linux.cn/article-3186-1.html https://www.howtogeek.com/190773/htg-explains-whats-the-differe ...
- android stadio 快捷键最好的材料 android stadio大全 最牛逼的android stadio快捷键
一: .nn .if .for .toast .instanceof .switch 这些都是可以直接点的,一个变量然后.for ,如果这个这个变量是个集合,都可以.for 二: 关闭所有窗口 ctr ...
- 腾讯装扮下拉选项卡特效(QQ空间)
<DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" ...
- ScrollView中ViewPager无法正常滑动问题
本文主要介绍如何解决ViewPager在ScrollView中滑动经常失效.无法正常滑动问题. 解决方法只需要在接近水平滚动时ScrollView不处理事件而交由其子View(即这里的ViewPage ...
- Jforum环境搭建
前提:搭建好JDK.JRE.Tomcat.数据库 1.之前安装了Navicat Premium,所以直接用这个创建名为jforum的MySQL数据库,默认密码为空,记得设置密码,因为Jforum要用到 ...
- Linux认知之旅【04 进一步了解目录】!
一.目录是什么? 二.不得不提的文件系统! 三.绝对路经,相对路径
- DataSource的设置
1.Centos和redhat,Fedora等版本无须设置,直接在cloud.cfg指定,默认是EC2 datasource_list: ['ConfigDrive','OpenStack'] 2.u ...
- [类和对象]3 C++面向对象模型初探
? C++编译器如何完成面向对象理论到计算机程序的转化? [C++编译器是如何管理类.对象.类和对象之间的关系] 通过下面的代码,我们可以的得出:C++类对象中的成员变量和成员函数是分开存储的 成员变 ...