[题解]UVA10986 Sending email
链接: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的更多相关文章
- uva 10986 - Sending email(最短路Dijkstra)
题目连接:10986 - Sending email 题目大意:给出n,m,s,t,n表示有n个点,m表示有m条边,然后给出m行数据表示m条边,每条边的数据有连接两点的序号以及该边的权值,问说从点s到 ...
- Sending e-mail with Spring MVC---reference
reference from:http://www.codejava.net/frameworks/spring/sending-e-mail-with-spring-mvc Table of con ...
- 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. ...
- Sending Email In .NET Core 2.0
Consider the following written in .NET Core 2.0. SmtpClient client = ) { UseDefaultCredentials = tru ...
- UVA 10896 Sending Email
这个题目真是伤透脑筋了,一直RE,连着改了好几个版本,又是spfa,又是单调队列dijkstra+单调队列,总是不过,后来发现M开小了,双向边应该开m的两倍,悲剧啊!!!以后不管怎样,数组一定要尽量开 ...
- UVa 10986 - Sending email
题目大意:网络中有n个SMTP服务器,有m条电缆将它们相连,每条电缆传输信息需要一定的时间.现在给出信息的起点和终点,计算所需的最小时间. 有权图上的单源最短路问题(Single-Source Sho ...
随机推荐
- Netlib文件转化为mps文件
Netlib文件转化为mps文件 简单方法1 下载并执行: git clone https://github.com/mtanneau/Netlib_experiments.git cd Netlib ...
- 【白话科普】《逆局》最终 boss 隐藏自己的方式是?
二狗子最近在看一个很火的电视剧<逆局>.作为一部悬疑犯罪剧,剧中多个案件交织并进,悬念和转折拉满,让狗子看的直呼过瘾.特别最后一幕,杨副座和主角团同时对 U 盘中的关键证据"器官 ...
- 【记录一个问题】神坑,自定义一个golang的error类型,居然运行崩溃了
2020-05-20 18:20补充: 感谢yif同学提供指导,出现错误并且打印大量信息的原因是函数递归调用导致栈溢出. 而导致递归调用的关键代码是%v 类型实现了error的interface %v ...
- 【记录一个问题】macos下lldb调试opencv的一个程序,出现“failed to load objfile for”错误,并且无法调试进入opencv的函数
opencv编译使用了Debug版本,打开了BUILD_WITH_DEBUG_INFO=ON选项. 发现问题后,我又在CMAKE_CXX_FLAGS_DEBUG中设置为 -g -ggdb3,在CMAK ...
- android ndk下没有pthread_yield,好在std::this_thread::yield()可以达到同样的效果
一个多线程的算法中,发现线程利用率只有47%左右,大量的处理时间因为usleep(500)而导致线程睡眠: 性能始终上不去. 把usleep(500)修改为std::this_thread::yiel ...
- 深入理解http1.x、http 2和https
转自 https://segmentfault.com/a/1190000015316332 一.HTTP/1.x Http1.x 缺陷:线程阻塞,在同一时间,同一域名的请求有一定数量限制,超过限制数 ...
- 539. Minimum Time Difference
Given a list of 24-hour clock time points in "Hour:Minutes" format, find the minimum minut ...
- linux可用内存判断
free是完全没有占用的空闲内存,Available 减 free是操作系统为了优化运行速度拿来调用的内存, 程序需要的话操作系统会进行释放.所以一般看Available即可. free+buffer ...
- oracle 相关查询和非相关查询,oracle 去除重复数据,以及oracle的分页查询!
一.oracle中的相关查询?和非相关查询? 二.oracle去除重复数据 1. 2. 3.oracle 实现分页? 利用rownum的唯一性,和子查询,将rownum从伪列变成实际列!
- ApacheCN 编程/大数据/数据科学/人工智能学习资源 2019.12
公告 我们的所有非技术内容和活动,从现在开始会使用 iBooker 这个名字. "开源互助联盟"已终止,我们对此表示抱歉和遗憾.除非特地邀请,我们不再推广他人的任何项目. 公众号自 ...