链接:http://vjudge.net/problem/viewProblem.action?id=24941

描述:n个点,m条边的无向图,寻找从S到T的最短路。

思路:基础的单源点最短路 用Dijkstra或spfa都可以解决

这是我的实现:

  1 #include <iostream>
2 #include <cstdio>
3 #include <cstring>
4 #include <queue>
5 using namespace std;
6 #define MaxN 20020
7 #define MaxM 100020
8 struct node
9 {
10 int v,dist;
11 node *next;
12 };
13 node Edge[MaxM];
14 node *cnt=&Edge[0];
15 node *adj[MaxN];
16 int dist[MaxN];
17 int N,INF;
18 int n,m,S,T;
19 inline void Get_int(int &Ret)
20 {
21 char ch;
22 bool flag=false;
23 for(;ch=getchar(),ch<'0'||ch>'9';)
24 if(ch=='-')
25 flag=true;
26 for(Ret=ch-'0';ch=getchar(),ch>='0'&&ch<='9';Ret=Ret*10+ch-'0');
27 flag&&(Ret=-Ret);
28 }
29 inline void Clean()
30 {
31 memset(Edge,0,sizeof(Edge));
32 cnt=&Edge[0];
33 memset(adj,0,sizeof(adj));
34 }
35 inline void Addedge(int u,int v,int w)
36 {
37 node *p=++cnt;
38 p->v=v;
39 p->dist=w;
40 p->next=adj[u];
41 adj[u]=p;
42
43 p=++cnt;
44 p->v=u;
45 p->dist=w;
46 p->next=adj[v];
47 adj[v]=p;
48 }
49 inline void Read_Build()
50 {
51 Get_int(n);Get_int(m);Get_int(S);Get_int(T);
52 int i,u,v,w;
53 for(i=1;i<=m;++i)
54 {
55 Get_int(u);Get_int(v);Get_int(w);
56 Addedge(u,v,w);
57 }
58 }
59 struct cmp
60 {
61 bool operator()(node a,node b)
62 {
63 return a.dist>b.dist;
64 }
65 };
66 priority_queue <node, vector<node>, cmp> q;
67 void Dijkstra(int s)
68 {
69 node c,d;
70 node *p;
71 int i,j,k;
72 memset(dist,0x3f,sizeof(dist));
73 INF=dist[s];
74 dist[s]=0;
75 c.v=s;c.dist=0;
76 q.push(c);
77 while(!q.empty())
78 {
79 d=q.top();q.pop();
80 j=d.v;
81 for(p=adj[j];p!=NULL;p=p->next)
82 {
83 k=p->v;
84 if(dist[k]>dist[j]+p->dist)
85 {
86 dist[k]=dist[j]+p->dist;
87 d.v=k;d.dist=dist[k];
88 q.push(d);
89 }
90 }
91 }
92 }
93 inline void Print()
94 {
95 if(dist[T]==INF)
96 printf("unreachable\n");
97 else
98 printf("%d\n",dist[T]);
99 }
100 int main()
101 {
102 Get_int(N);
103 for(int i=1;i<=N;i++)
104 {
105 printf("Case #%d: ",i);
106 Clean();
107 Read_Build();
108 Dijkstra(S);
109 Print();
110 }
111 return 0;
112 }

[题解]UVA10986 Sending email的更多相关文章

  1. uva 10986 - Sending email(最短路Dijkstra)

    题目连接:10986 - Sending email 题目大意:给出n,m,s,t,n表示有n个点,m表示有m条边,然后给出m行数据表示m条边,每条边的数据有连接两点的序号以及该边的权值,问说从点s到 ...

  2. Sending e-mail with Spring MVC---reference

    reference from:http://www.codejava.net/frameworks/spring/sending-e-mail-with-spring-mvc Table of con ...

  3. Sending e-mail with Spring MVC--转载

    原文地址:http://www.codejava.net/frameworks/spring/sending-e-mail-with-spring-mvc Table of contents: 1.S ...

  4. 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 ...

  5. Spring – Sending E-Mail Via Gmail SMTP Server With MailSender--reference

    Spring comes with a useful ‘org.springframework.mail.javamail.JavaMailSenderImpl‘ class to simplify ...

  6. Sending e-mail

    E-mail functionality uses the Apache Commons Email library under the hood. You can use theplay.libs. ...

  7. Sending Email In .NET Core 2.0

    Consider the following written in .NET Core 2.0. SmtpClient client = ) { UseDefaultCredentials = tru ...

  8. UVA 10896 Sending Email

    这个题目真是伤透脑筋了,一直RE,连着改了好几个版本,又是spfa,又是单调队列dijkstra+单调队列,总是不过,后来发现M开小了,双向边应该开m的两倍,悲剧啊!!!以后不管怎样,数组一定要尽量开 ...

  9. UVa 10986 - Sending email

    题目大意:网络中有n个SMTP服务器,有m条电缆将它们相连,每条电缆传输信息需要一定的时间.现在给出信息的起点和终点,计算所需的最小时间. 有权图上的单源最短路问题(Single-Source Sho ...

随机推荐

  1. python极简教程07:封装、多态和继承

    测试奇谭,BUG不见. 这一场主讲python的面向对象部分--封装.多态和继承. 目的:掌握Python面向对象的三个核心概念. 封装 01 什么是封装? 封装的目的是,保护隐私.通俗的讲:不想让别 ...

  2. django_templates模板与html页

    新建应用 上一篇通过"django-admin startproject helloworld"是创建项目,一个项目下可以有多个应用(app).打开cmd,cd到manage.py ...

  3. 记一次redis 基于spring实现类对同一个KEY序列化内容不同导致一次事故

    我们的场景是这样的 我们对一个key:比如list.point.card:1 @Resourceprivate RedisTemplate<String, Long> redisTempl ...

  4. linux中yum本地私有仓库安装搭建《全面解析》

    目录 一:yum本地仓库安装 1.yum简介 2.yum安装解析 二:yum安装的生命周期 三:yum私有仓库作用与必要性 四:搭建yum私有仓库 本地版本 1.下载必须的软件包 2.创建软件仓库(就 ...

  5. 使用 electron 和 electron-forge 加载 本地磁盘资源 img 的问题

    最近在学习使用 electron 进行桌面开发一款图片压缩的软件.遇到了加载本地磁盘文件的问题.记录一下其解决方案. 使用 electron 加载本地磁盘文件 第一种方法 设置webPreferenc ...

  6. Java IO: ByteArrayOutputStream使用

    感谢原文作者:小思思smile 原文链接:https://blog.csdn.net/u014049880/article/details/52329333/ 更多请查阅Java API文档! 在创建 ...

  7. js instanceof 解析

    js中的instanceof运算符 概述 instanceof运算符用来判断一个构造函数的prototype属性所指向的对象是否存在另外一个要检测对象的原型链上 语法 obj instanceofOb ...

  8. 浅谈AngularJS中使用$resource

    这个服务可以创建一个资源对象,我们可以用它非常方便地同支持RESTful的服务端数据源进行交互,当同支持RESTful的数据模型一起工作时,它就派上用场了. REST是Representational ...

  9. 使用 Element UI Select 组件的 value-key 属性,让绑定值可以为一个对象

    EsunR 2019-11-07 12:14:42  12264  收藏 6 分类专栏: Vue 文章标签: element-ui 版权 当我们使用 Elemet UI 的选择组件进行多选时,Sele ...

  10. VUE3 之 动态组件 - 这个系列的教程通俗易懂,适合新手

    1. 概述 暗示效应告诉我们: 巧妙的暗示会在不知不觉中剥夺我们的判断力,对我们的思维形成一定的影响,造成我们行为的些许改变或者偏差. 例如你的朋友说你脸色不太好,是不是病了,此时,你可能就会感觉浑身 ...