图论
文章平均质量分 80
新西兰做的饭
Here we go!
展开
-
PTA-最短路径(1003/1018/1030/1072/1087)
1003 Emergency (25 分)As an emergency rescue team leader of a city, you are given a special map of your country. The map shows several scattered cities connected by some roads. Amount of rescue teams in each city and the length of each road between any pai原创 2022-03-04 19:24:35 · 833 阅读 · 0 评论 -
通过四道编程题总结图的搜索(DFS/BFS)——PTA(1013/1021/1034/1076)
1013 Battle Over Cities (25 分)It is vitally important to have all the cities connected by highways in a war. If a city is occupied by the enemy, all the highways from/toward that city are closed. We must know immediately if we need to repair any other hig原创 2022-02-28 01:19:45 · 559 阅读 · 0 评论 -
PTA-1030 Travel Pla(使用堆优化的dijkstra算法)
PTA-1030 Travel Plan (30 分)A traveler’s map gives the distances between cities along the highways, together with the cost of each highway. Now you are supposed to write a program to help a traveler to decide the shortest path between his/her starting cit.原创 2021-05-31 20:39:42 · 139 阅读 · 0 评论 -
PTA-1003 Emergency(使用堆优化的dijkstra算法)
#include<bits/stdc++.h>using namespace std;#define INF 0x3f3f3f3fconst int maxx=505;struct edge{ int to,dis,cost; edge(int _to,int _dis,int _cost){to=_to,dis=_dis,cost=_cost;}};vector<edge> a[maxx];typedef pair<int ,int> P;int原创 2021-05-25 19:38:26 · 134 阅读 · 0 评论 -
挑战程序设计竞赛最短路习题及详解(C++实现)
最短路径Aizu - 0189 Convenient LocationPOJ - 2139 Six Degrees of Cowvin BaconPOJ - 3259 WormholesPOJ - 3268 Silver Cow PartyAizu - 2249 Road Construction总结Aizu - 0189 Convenient Location弗洛伊德模板题#include<iostream>#include<algorithm>using namespa原创 2021-05-24 09:36:38 · 363 阅读 · 0 评论 -
挑战程序设计竞赛最小生成树习题(4道)及详解:C++实现
最小生成树POJ 1258:Agri-NetPOJ 2377:Bad CowtractorsPOJ 2395:Out of HayAOJ 2224:Save your cats这四道题比较基本,没有过多复杂的过程,所以整合在一篇博客,适合学过最小生成树算法后来加深理解POJ 1258:Agri-Net点击进入题面最小生成树模板题,输入为图的邻接矩阵,所以优先考虑prim算法:#include<iostream>#include<algorithm>using name原创 2021-05-17 16:27:23 · 404 阅读 · 0 评论 -
图文详解最小生成树算法并利用并查集实现Kruskal算法(C++实现)
最小生成树Prim算法Kruskal算法最小生成树即在连通图中用n-1条边连接全部n个顶点,生成无环路的树形结构,并使得连接边的权值之和最小。我们介绍最小生成树的经典算法:普里姆算法和克鲁斯卡尔算法。Prim算法普里姆算法从图的一个顶点出发,将此顶点归入集合,并不断选取图中其他顶点到已添加顶点的最短路径,将添加的最短路径归入最小生成树中,待所有顶点归入集合,即生成n个顶点n-1条边的最小生成树。//针对图的邻接矩阵的普里姆算法void MiniSpanTree_Prim(MGraph G){原创 2021-05-14 20:10:43 · 761 阅读 · 2 评论