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 == 0 ? 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 = 0; 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] = 0;
   // 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 = 0; 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 = 1;
    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 0;
}
时间: 2024-10-07 19:46:02

UVA 10986 Sending email 最短路问题的相关文章

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

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

UVA 10986 Sending email 【dijkstra + 堆优化】

题目链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1927 题意:n个点m条边,求s到e的最短距离 代码: #include<stdio.h> #include<iostream> #include<math.h> #include<stdlib.h> #include<cty

UVa 10986 - Sending email

链接:http://uva.onlinejudge.org/index.php? option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1927 //邻接表+队列 #include <iostream> #include <string.h> #include <queue> #include <stdio.h> using namespac

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.

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

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.