[题目链接]

https://www.spoj.com/problems/ADATRIP/

[算法]

直接使用dijkstra堆优化算法即可

[代码]

#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + ;
const int INF = 2e9; struct edge
{
int to,w,nxt;
} e[MAXN << ]; int i,j,tot,a,b,l,n,m,u,q;
int head[MAXN];
pair<int,int> ans; inline void addedge(int u,int v,int w)
{
tot++;
e[tot] = (edge){v,w,head[u]};
head[u] = tot;
}
inline pair<int,int> dijkstra(int s)
{
int i,l,r,cur,ans1,ans2,v,w;
static int dist[MAXN];
static bool visited[MAXN];
priority_queue< pair<int,int> > q;
for (i = ; i < n; i++)
{
dist[i] = INF;
visited[i] = false;
}
q.push(make_pair(,s));
dist[s] = ;
while (!q.empty())
{
cur = q.top().second;
q.pop();
if (visited[cur]) continue;
visited[cur] = true;
for (i = head[cur]; i; i = e[i].nxt)
{
v = e[i].to;
w = e[i].w;
if (dist[cur] + w < dist[v])
{
dist[v] = dist[cur] + w;
q.push(make_pair(-dist[v],v));
}
}
}
ans1 = ;
for (i = ; i < n; i++)
{
if (dist[i] != INF)
ans1 = max(ans1,dist[i]);
}
ans2 = ;
for (i = ; i < n; i++)
{
if (dist[i] == ans1)
ans2++;
}
return make_pair(ans1,ans2);
} int main()
{ scanf("%d%d%d",&n,&m,&q);
for (i = ; i <= m; i++)
{
scanf("%d%d%d",&a,&b,&l);
if (l == ) continue;
addedge(a,b,l);
addedge(b,a,l);
}
while (q--)
{
scanf("%d",&u);
ans = dijkstra(u);
printf("%d %d\n",ans.first,ans.second);
} return ; }

[SPOJ 30669] Ada and Trip的更多相关文章

  1. SPOJ:Ada and Orange Tree (LCA+Bitset)

    Ada the Ladybug lives near an orange tree. Instead of reading books, she investigates the oranges. T ...

  2. SPOJ ADAFIELD Ada and Field(STL的使用:set,multiset,map的迭代器)题解

    题意:n*m的方格,“0 x”表示x轴在x位置切一刀,“0 y”表示y轴在y位置切一刀,每次操作后输出当前面积最大矩形. 思路:用set分别储存x轴y轴分割的点,用multiset(可重复)储存x轴y ...

  3. @spoj - ADAMOLD@ Ada and Mold

    目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定一个长度为 N 的序列 A,将其划分成 K + 1 段,划分 ...

  4. SPOJ:Ada and Graft (set合并&优化)

    As you might already know, Ada the Ladybug is a farmer. She grows a big fruit tree (with root in 0). ...

  5. 【SPOJ】1825. Free tour II(点分治)

    http://www.spoj.com/problems/FTOUR2/ 先前看了一会题解就自己yy出来了...对拍过后交tle.................. 自己造了下大数据........t ...

  6. POJ 1511 Invitation Cards / UVA 721 Invitation Cards / SPOJ Invitation / UVAlive Invitation Cards / SCU 1132 Invitation Cards / ZOJ 2008 Invitation Cards / HDU 1535 (图论,最短路径)

    POJ 1511 Invitation Cards / UVA 721 Invitation Cards / SPOJ Invitation / UVAlive Invitation Cards / ...

  7. spoj 1825 Free tour II

    http://www.spoj.com/problems/FTOUR2/ After the success of 2nd anniversary (take a look at problem FT ...

  8. SPOJ:Free tour II (树分治+启发式合并)

    After the success of 2nd anniversary (take a look at problem FTOUR for more details), this 3rd year, ...

  9. SPOJ Free TourII(点分治+启发式合并)

    After the success of 2nd anniversary (take a look at problem FTOUR for more details), this 3rd year, ...

随机推荐

  1. 闲谈Spring-IOC容器

    闲聊 无论是做j2ee开发还是做j2se开发,spring都是一把大刀.当下流行的ssh三大框架中,spring是最不可替代的,如果不用hibernate和struts,我觉得都无关紧要,但是不能没有 ...

  2. 详细解读css中的浮动以及清除浮动的方法

    对于前端初学者来说,css浮动部分的知识是一块比较难以理解的部分,下面我将把我学习过程中的心得分享给大家. 导读:   1.css块级元素讲解 2.css中浮动是如何产生的 3.出现浮动后,如何清除浮 ...

  3. React+Dva

    Reducer reducer 是一个函数,接受 state 和 action,返回老的或新的 state .即:(state, action) => state Effect app.mode ...

  4. python--8、socket网络编程

    socket socket可以完成C/S架构软件的开发.须知一个完整的计算机系统是由硬件.操作系统.应用软件三者组成,具备了这三个条件,一台计算机就可以工作了.但是要跟别人一起玩,就要上互联网(互联网 ...

  5. 微信公众号API使用总结

    官网:    https://mp.weixin.qq.com/ API:          http://mp.weixin.qq.com/wiki/home/index.html 接口调试工具:h ...

  6. OpenCV:Python3使用OpenCV

    Python3使用OpenCV安装过程应该是这样的,参考:http://blog.csdn.net/lixintong1992/article/details/61617025    ,使用conda ...

  7. OpenCV向JNI层的参数转换

    九层之台,起于累土:千里之堤毁于蚁穴:成者半于九十.最近工程项目完全可以调试,却最后在 OpenCV向JNI层的参数转换 这个节点上遇到麻烦,看来得好好的思考一番,仔细寻找其中的纰漏. 一.实例 根据 ...

  8. 【sqli-labs】 less36 GET- Bypass MYSQL_real_escape_string (GET型绕过MYSQL_real_escape_string的注入)

    看一下mysql_real_escape_string()函数 \x00 \x1a 注入的关键还是在于闭合引号,同样使用宽字节注入 http://192.168.136.128/sqli-labs-m ...

  9. 【转载】Servlet中的request与response

      一.HttpServletRequest概述   1.1.HttpServletRequest简介 HttpServletRequest对象代表客户端的请求,当客户端通过HTTP协议访问服务器时, ...

  10. C#第十二节课

    数组 using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Th ...