[题目链接]

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. ★Java语法(四)——————————运算符

    使用除法“/”  ,要特别注意数据类型的问题.若被除数和除数都是整形,且被除数不能被除数整除时,这时输出的结果为整数,(即整形数/整形数=整形数),这是因为整形变量无法保存小数点后面的数据所致,要特别 ...

  2. Eclipse代码自动提示(内容辅助content assist)

    Eclipse中默认是输入"."后出现自动提示,用于类成员的自动提示,可是有时候我们希望它能在我们输入类的首字母后就出现自动提示,可以节省大量的输入时间(虽然按alt + /会出现 ...

  3. JavaScript自动计算价格和全选

    JavaScript自动计算价格和全选,价格自增加减,复选框,反选,全选. 如图: 如图: CSS代码 @charset "gb2312"; /* CSS Document */ ...

  4. 与Java注释相关的一些知识

    * Html标签:        * <a> 可定义锚,主要有以下两种属性            * href(最重要):创建指向另外一个文档的链接(或超链接)            * ...

  5. 团体程序设计天梯赛-练习集-L1-047. 装睡

    L1-047. 装睡 你永远叫不醒一个装睡的人 —— 但是通过分析一个人的呼吸频率和脉搏,你可以发现谁在装睡!医生告诉我们,正常人睡眠时的呼吸频率是每分钟15-20次,脉搏是每分钟50-70次.下面给 ...

  6. 记Python学习

    上周学的Python,感觉有点忘了,现在回顾一下... 一.Python安装及测试:https://www.cnblogs.com/weven/p/7252917.html 例子: Python自带的 ...

  7. BZOJ 1864: [Zjoi2006]三色二叉树 树形DP + 读入

    Description Input 仅有一行,不超过500000个字符,表示一个二叉树序列. Output 输出文件也只有一行,包含两个数,依次表示最多和最少有多少个点能够被染成绿色. 题解:本题大水 ...

  8. Jmeter的参数签名测试

    简介 参数签名可以保证开发的者的信息被冒用后,信息不会被泄露和受损.原因在于接入者和提供者都会对每一次的接口访问进行签名和验证. 签名sign的方式是目前比较常用的方式. 第1步:接入者把需求访问的接 ...

  9. eas之执行sql的方式

    客户端:    1. 有返回集合:查询     //查询出DB中所有该字段的值,与其进行比较,若有相同的则报错      String sql="select CFWuliaoCode fr ...

  10. 6.2 C# 2:利用 yield 语句简化迭代器

    class Program { static void Main(string[] args) { object[] values = new object[] { "a", &q ...