A*+SPFA算法:
(1)将有向图的所有边正向、反向分别存入两个不同的边集(Edges,Edges1)中。用反向边集,以所求终点t为源点,利用SPFA或Dijkstra求解出所有点到t的最短路径,用Dist[i]数组来表示点i到点t的最短距离。
(2)建立一个优先队列,将源点s加入到队列中。
(3)从优先队列中取出最小的点p,如果点p == t,则计算t出队的次数。如果当前路径长度就是s到t...
分类:
其他好文 时间:
2015-05-05 00:09:25
阅读次数:
128
Kruskal算法struct Edge
{
int from;
int to;
int w;
}; Edge Edges[200200]; int father[200200],N,M; int find(int x)
{
if(x != father[x])
father[x] = find(father[x]...
分类:
其他好文 时间:
2015-05-03 00:51:15
阅读次数:
211
Description
A thief is running away!
We can consider the city where he locates as an undirected graph in which nodes stand for crosses and edges stand for streets. The crosses are labeled from 0 ...
分类:
其他好文 时间:
2015-05-02 22:06:46
阅读次数:
204
Description
You are given a graph with N nodes and M edges.
Then every time you are required to add an additional edge with weight Wi connecting the node Ai and Bi in the graph, and then calculat...
分类:
其他好文 时间:
2015-04-22 09:40:45
阅读次数:
140
Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are all surrounded by water....
分类:
其他好文 时间:
2015-04-09 10:41:17
阅读次数:
185
DescriptionGiven a directed graph containing n vertice (numbered from 1 to n) and m edges. Can you tell us how many different Hamiltonian Cycles are t...
分类:
其他好文 时间:
2015-04-06 21:34:45
阅读次数:
144
裸的最小生成树..直接跑就行了----------------------------------------------------------------------#include#include#include#define rep(i,n) for(int i=0;i edges; vo....
分类:
其他好文 时间:
2015-03-22 00:12:44
阅读次数:
155
题目链接:点击打开链接
题意:
给出n个点m条无向边的图
开始图里没有边,每次加一条边,然后输出图里欧拉回路的条数。
思路:
We will count the number of ski bases including the base consisted of empty subset of edges (before printing just subtract one)....
分类:
其他好文 时间:
2015-03-18 23:21:31
阅读次数:
233
function Graph(v) { this.vertices = v; //初始化顶点 this.edges = 0; //边数先设置为0 this.adj = []; //为每一个顶点准备一个链表,表示它和所有节点的关系 for (var i = 0...
分类:
编程语言 时间:
2015-03-18 17:42:17
阅读次数:
377
题目链接:http://poj.org/problem?id=3237You are given a tree withNnodes. The tree’s nodes are numbered 1 throughNand its edges are numbered 1 throughN? 1. ...
分类:
其他好文 时间:
2015-03-17 19:39:28
阅读次数:
182