[题解]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

时间: 2024-10-14 05:23:53

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

UVA10986 - Sending email(Dijkstra)

题目链接 题目大意:给n个点,m条边,还有起点和终点,问起点到终点的最短距离,不可达unreachable. 解题思路:最短路问题,dijkstra算法. 代码: #include <cstdio> #include <queue> #include <vector> #include <string.h> using namespace std; using std::make_pair; typedef pair<int, int> pii;

UVA 10986 Sending email(SPFA)

There are n SMTP servers connected by network cables. Each of the m cables connects two computers and has a certain latency measured in milliseconds required to send an email message. What is the shortest time required to send a message from server S

Sending e-mail with Spring MVC--转载

原文地址:http://www.codejava.net/frameworks/spring/sending-e-mail-with-spring-mvc Table of contents: 1.Spring framework’s support for e-mail 2.Required jar files 3.Creating e-mail sending form 4.Configuring SMTP server settings and Spring MVC 5.Creating

check-mk is not sending email

http://ubuntuforums.org/showthread.php?t=1971360 The problem is the DNS is not resolving (out off the domain) changed the domain to localhost and use smtp relay to recover sending email notifications.

uva 10986 Sending email (dijkstra)

uva 10986 Sending email "A new internet watchdog is creating a stir in Springfield. Mr. X, if that is his real name, has come up with a sensational scoop."Kent Brockman There are n SMTP servers connected by network cables. Each of the m cables c

Sending e-mail with Spring MVC---reference

reference from:http://www.codejava.net/frameworks/spring/sending-e-mail-with-spring-mvc Table of contents: 1.Spring framework’s support for e-mail 2.Required jar files 3.Creating e-mail sending form 4.Configuring SMTP server settings and Spring MVC 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 the e-mail sending process via JavaMail API. Here’s a Maven build project to use Spring’s ‘JavaMailSenderImpl‘ to send an email via Gmail SMTP server.

Sending e-mail

E-mail functionality uses the Apache Commons Email library under the hood. You can use theplay.libs.Mail utility class to send e-mail very easily. A simple e-mail: SimpleEmail email = new SimpleEmail(); email.setFrom("[email protected]"); email.

Sending Email In .NET Core 2.0

Consider the following written in .NET Core 2.0. 1 SmtpClient client = new SmtpClient("smtp.exmail.qq.com", 587) 2 { 3 UseDefaultCredentials = true, 4 Credentials = new NetworkCredential("[email protected]", "yHbgby"), 5 Enab