[题目链接]

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. 复习HTML+CSS(8)

    n  普通框架 框架技术:将一个浏览器划分成若干个小窗口,每个小窗口显示一个独立的网页. 框架集合框架页 u  框架集<frameset>:主要用来划分窗口的. u  框架页<fra ...

  2. Android5.1关机充电界面尺寸修改

    Android5.1关机充电界面尺寸修改 因为项目的屏幕尺寸和一般的手机屏幕不一样,因此关机充电界面在设备上运行后严重变形,就需要自己修改这个界面了,废话不多说了,开打开打! 首先要说明这里是以And ...

  3. Caffe: gflag编译出现问题汇总

    1. 使用Unicode字符集: 出现问题 E:\CodeBase\ML\Caffe\ThirdPartySrc\gflags-master\src\gflags.cc(1340): error C2 ...

  4. (转)Bootstrap 之 Metronic 模板的学习之路 - (3)源码分析之 body 部分

    https://segmentfault.com/a/1190000006697252 body 的组成结构 body 部分包含了 HEADER.CONTAINER.FOOTER,其中 CONTAIN ...

  5. Postgresql_最新版11.2源码编译安装

    pg官网:https://www.postgresql.org/ yum -y gcc gcc-c++ cmake ncurses-devel perl zlib* .去官网下载源码包. 下载地址:h ...

  6. BZOJ 4698: Sdoi2008 Sandy的卡片 后缀数组 + RMQ + 查分

    题目描述 Sandy和Sue的热衷于收集干脆面中的卡片. 然而,Sue收集卡片是因为卡片上漂亮的人物形象,而Sandy则是为了积攒卡片兑换超炫的人物模型. 每一张卡片都由一些数字进行标记,第i张卡片的 ...

  7. eas之设置编辑界面分录的某一列不可编辑

    KDTEntrys.getColumn(“xx”).getStayAttributes().setlokced(true);

  8. Codeforces Round #406 (Div. 2) 787-D. Legacy

    Rick and his co-workers have made a new radioactive formula and a lot of bad guys are after them. So ...

  9. [luogu2414 NOI2011]阿狸的打字机 (AC自动机)

    传送门 Solution 我们知道AC自动机上如果有一点A的fail[A]->B那么B为A的一个后缀 那么我们的问题\((x,y)\)就变为在y中有多少个点直接或间接连向x的终止节点 如果写暴力 ...

  10. Redis学习笔记(一)-持久化

    一.RDB持久方式 RDB持久化是把当前进程的数据已快照的形式保存到硬盘的过程. 触发方式: 1.手动触发命令:save和bgsave save:阻塞式,内存较大的实例在执行过程中会造成长时间的阻塞, ...