题目链接 多次询问求仙人掌上两点间的最短路径. 如果是在树上,那么求LCA就可以了. 先做着,看看能不能把它弄成树. 把仙人掌看作一个图(实际上就是),求一遍根节点到每个点的最短路dis[i]. 对于u,v,若w=LCA(u,v)不在环上(u,v不同在一个环),那么dis(u,v)可以像在树上一样直接求得. 若w=u||w=v,(且w不是环内的一个点),dis(u,v)=dis[u/v]-dis[w]. 如果w在环上,那么设x,y为u,v往上距离最近的环上的离u,v最近的两个点,那么dis(u,…
/*  *题目大意:  *在一个有向图中,求从s到t两个点之间的最短路和比最短路长1的次短路的条数之和;  *  *算法思想:  *用A*求第K短路,目测会超时,直接在dijkstra算法上求次短路;  *将dist数组开成二维的,即dist[v][2],第二维分别用于记录最短路和次短路;  *再用一个cnt二维数组分别记录最短路和次短路的条数;  *每次更新路径的条数时,不能直接加1,,应该加上cnt[u][k],k为次短路径或者最短路径的标记;  *图有重边,不能用邻接矩阵存储;  *不知道…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1688 题意:第k短路,这里要求的是第1短路(即最短路),第2短路(即次短路),以及路径条数,最后如果最短路和次短路长度差1,则输出两种路径条数之和,否则只输出最短路条数. 思路:dijkstra变形,注意状态的转移,代码上附了注释,就不多说了.. 代码: #include <bits/stdc++.h> #define MAXN 1010 using namespace std; vector&l…
严格次短路模板,用两个数组分别维护最短路和次短路,用dijskstra,每次更新的时候先更新最短路再更新次短路 写了spfa版的不知道为啥不对-- #include<iostream> #include<cstdio> #include<queue> using namespace std; const int N=5005,inf=1e9; int n,m,h[N],cnt,d1[N],d2[N]; struct qwe { int ne,to,va; }e[2000…
http://poj.org/problem?id=3463 Sightseeing Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6420   Accepted: 2270 Description Tour operator Your Personal Holiday organises guided bus trips across the Benelux. Every day the bus moves from…
Sightseeing Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9247   Accepted: 3242 Description Tour operator Your Personal Holiday organises guided bus trips across the Benelux. Every day the bus moves from one city S to another city F. O…
题目 Tour operator Your Personal Holiday organises guided bus trips across the Benelux. Every day the bus moves from one city S to another city F. On this way, the tourists in the bus can see the sights alongside the route travelled. Moreover, the bus…
最短路 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) 在每年的校赛里,所有进入决赛的同学都会获得一件很漂亮的T-shirt.但是每当我们的工作人员把上百件的衣服从商店运回到赛场的时候,却是非常累的!所以现在他们想要寻找最短的从商店到赛场的路线,你可以帮助他们吗? Input 输入包括多组数据. 每组数据第一行是两个整数NN ,MM (N≤100N≤100 ,M≤10000M≤1000…
C. Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from t…
F - Sightseeing 传送门: POJ - 3463 分析 一句话题意:给你一个有向图,可能有重边,让你求从s到t最短路的条数,如果次短路的长度比最短路的长度多1,那么在加上次短路的条数. 这道题唯一要注意的就是次短路的求法 首先题目中说从起点到终点至少有一条路径,所以我们就不用考虑不可达的情况 我们先考虑如果a到b有一条边,b到c有一条边 那么a到c经过b的路程中次短路只有两种选择,一种是a到b的最短路+b到c的次短路,另一种是a到b的次短路+b到c的次短路 所以我们只需要记录次短路…