![](https://img-blog.csdnimg.cn/20201014180756913.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
ACM-图论
文章平均质量分 72
hahahahhahello
这个作者很懒,什么都没留下…
展开
-
FZU - 2141 Sub-Bipartite Graph (二分图+贪心)
题意:给出n个点,m条边,找出一个子二分图,让这个子二分图的变数至少为m/2,题目保证一定存在这样的子二分图。题目中给了二分图与子图的定义,二分图的定义是:如果一个图的所有顶点可以被分为U V两个集合,并且所有边的两个顶点恰好一个属于U,一个属于Y,即每个集合内的顶点没有边相连,那么此图就是二分图。二分图里并不含有奇圈。这道题贪心的来做,假设前i个点已经形成了二分图,再添加第i+1个点的时候,判断...原创 2018-04-14 19:52:35 · 193 阅读 · 0 评论 -
UVA - 1395 Slim Span (最小生成树)
题意:给出一个n个结点的图,求最大边减去最小边尽量小的生成树。思路:暴力最小的边,用Kruskal求最小生成树,维护最大边减去最小边的最小值#include <iostream>#include <cstdio>#include <algorithm>const int INF = 0x3f3f3f3f;using namespace std;int...原创 2018-04-14 21:09:38 · 162 阅读 · 0 评论 -
最小生成树Kruskal算法模板
int cmp(const int i,const int j){ return w[i] < w[j];}int find(int x){ return x == pre[x] ? x : pre[x] = find(pre[x]);}int join(int x,int y){ int fx = find(x); int fy = find(y); if(fx !=...原创 2018-04-14 21:32:40 · 163 阅读 · 0 评论 -
FZU - 2271 X (Floyd)
题意:给出n个点,m条边,在保持任意两点之间最短路径距离不变的情况下,最多可以去除多少边?思路:在输入数据的时候,可以去除一些边,因为我们只需要两个点之间距离最小的那条边,然后跑一遍Floyd算法,求出任意两点的最短路,如果两个点是直接相连,并且被松弛过,或者松弛之后的距离与两点直接相连的距离相等,我们就可以去除这条两点之间直接相连的边。#include<stdio.h>#inclu...原创 2018-04-17 16:34:25 · 292 阅读 · 0 评论 -
Dwarf Tower(最短路spfa)
题意:n件物品,获得第i件物品有两种方式,可以花费ci来购买,也可以用两件其它的物品来换取,输出获得第一件物品最少需要多少花费?思路:开始我考虑不周到,认为物品之间的换取关系是一个二叉树了,实际上是构成了一张图,图是这样构成的,假设a能用b和c物品来换取,那么mp[b][a] = cost[c] mp[c][a] = cost[b],对所有结点进行spfa#include <stdio.h&...原创 2018-04-09 23:15:21 · 150 阅读 · 0 评论 -
FZU - 2254 英语考试(最小生成树)
在过三个礼拜,YellowStar有一场专业英语考试,因此它必须着手开始复习。 这天,YellowStar准备了n个需要背的单词,每个单词的长度均为m。 YellowSatr准备采用联想记忆法来背诵这n个单词: 1、如果YellowStar凭空背下一个新词T,需要消耗单词长度m的精力 2、如果YellowSatr之前已经背诵了一些单词,它可以选择其中一个单词Si,然...原创 2017-10-03 17:02:12 · 370 阅读 · 0 评论 -
POJ-2253 Frogger(三种最短路和最小生成树)
POJ-2253 FroggerFreddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fiona Frog who is sitting on another stone. He plans to visit her, but since the water is dirty and full ...原创 2017-08-23 19:53:36 · 845 阅读 · 0 评论 -
最短路径问题 HDU - 3790 最短路
给你n个点,m条无向边,每条边都有长度d和花费p,给你起点s终点t,要求输出起点到终点的最短距离及其花费,如果最短距离有多条路线,则输出花费最少的。Input输入n,m,点的编号是1~n,然后是m行,每行4个数 a,b,d,p,表示a和b之间有一条边,且其长度为d,花费为p。最后一行是两个数 s,t;起点s,终点。n和m为0时输入结束。(1<n<=1000, 0<m<100...原创 2017-08-06 10:09:02 · 288 阅读 · 0 评论 -
Rank HDU - 1704 Floyd传递闭包
Rankthere are N ACMers in HDU team. ZJPCPC Sunny Cup 2007 is coming, and lcy want to select some excellent ACMers to attend the contest. There have been M matches since the last few days(No two ACMers...原创 2017-08-06 09:53:22 · 479 阅读 · 0 评论 -
CodeForces - 296D Greg and Graph 逆向思维+Floyd—Warshall
Greg and GraphGreg has a weighed directed graph, consisting of n vertices. In this graph any pair of distinct vertices has an edge between them in both directions. Greg loves playing with the graph an...原创 2017-08-06 09:33:36 · 279 阅读 · 0 评论 -
HDU - 2962 Trucking 最短路加二分
HDU - 2962 TruckingA certain local trucking company would like to transport some goods on a cargo truck from one place to another. It is desirable to transport as much goods as possible each trip. Unf...原创 2017-08-05 22:52:01 · 389 阅读 · 0 评论 -
HDU - 3499 Flight 最短路
HDU - 3499 Flight 最短路Recently, Shua Shua had a big quarrel with his GF. He is so upset that he decides to take a trip to some other city to avoid meeting her. He will travel only by air and he can go ...原创 2017-08-05 22:25:42 · 600 阅读 · 0 评论 -
HDU - 5137 How Many Maos Does the Guanxi Worth 最短路+深搜
How Many Maos Does the Guanxi Worth"Guanxi" is a very important word in Chinese. It kind of means "relationship" or "contact". Guanxi can be based on friendship, but also can be built on money. So Chi...原创 2017-08-04 23:22:01 · 306 阅读 · 0 评论 -
CodeForces - 449B Jzzhu and Cities 最短路
CodeForces - 449B Jzzhu and CitiesJzzhu is the president of country A. There are n cities numbered from1 ton in his country. City1 is the capital of A. Also there arem roads connecting the cities. On...原创 2017-08-04 22:47:46 · 364 阅读 · 0 评论 -
poj 3037 -- Skiing spfa
poj 3037 -- Skiing spfaBessie and the rest of Farmer John's cows are taking a trip this winter to go skiing. One day Bessie finds herself at the top left corner of an R (1 <= R <= 100) by C (1 &...原创 2017-08-01 21:22:08 · 434 阅读 · 0 评论 -
FZU - 2112 Tickets (欧拉通路+联通块)
题意:给出n个点,m条边,添加最少的边,可以不重复的走m条边一次思路:一笔画问题,就是求欧拉通路,欧拉通路:在无向连通图中,有0个或2个奇度顶点。如果有4个奇度顶点,我们只需在任意两个奇度点之间添加一条边就行,因为并没有说是连通图,所以如果有n个联通块的话,我们还需添加n-1条边。这道题不判断联通块也能过。。。。。。#include <iostream>#include <cs...原创 2018-04-13 09:45:17 · 168 阅读 · 0 评论 -
codeforces 813C The Tag Game
Alice got tired of playing the tag game by the usual rules so she offered Bob a little modification to it. Now the game should be played on an undirected rooted tree of n vertices. Vertex 1 is the roo...原创 2017-07-29 10:53:57 · 386 阅读 · 0 评论 -
Codeforces Round #398(Div. 2)C. Garland
Once at New Year Dima had a dream in which he was presented a fairy garland. A garland is a set of lamps, some pairs of which are connected by wires. Dima remembered that each two lamps in the garland...原创 2017-07-29 11:23:43 · 375 阅读 · 0 评论 -
HDU - 1495 BFS
大家一定觉的运动以后喝可乐是一件很惬意的事情,但是seeyou却不这么认为。因为每次当seeyou买了可乐以后,阿牛就要求和seeyou一起分享这一瓶可乐,而且一定要喝的和seeyou一样多。但seeyou的手中只有两个杯子,它们的容量分别是N 毫升和M 毫升 可乐的体积为S (S<101)毫升 (正好装满一瓶) ,它们三个之间可以相互倒可乐 (都是没有刻度的,且 S==N+M,10...原创 2017-07-30 09:24:11 · 279 阅读 · 0 评论 -
POJ - 3414 Pots BFS
POJ - 3414 PotsYou are given two pots, having the volume of A and B liters respectively. The following operations can be performed:FILL(i) fill the pot i (1 ≤i ≤ 2) from the tap;DROP(i) em...原创 2017-07-30 09:57:37 · 304 阅读 · 0 评论 -
UVA - 11624 Fire! 两次BFS
UVA - 11624 Fire!Joe works in a maze. Unfortunately, portions of the maze have caught on fire, and the owner of the maze neglected to create a fire escape plan. Help Joe escape the maze. Given Joe’s lo...原创 2017-07-30 10:12:58 · 496 阅读 · 0 评论 -
POJ - 2251 Dungeon Master BFS
POJ - 2251 Dungeon MasterYou are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of unit cubes which may or may not be filled with rock. It takes one minute to m...原创 2017-07-30 10:32:59 · 308 阅读 · 0 评论 -
HDU - 1175 连连看(dfs)
HDU - 1175 连连看(dfs) 连连看”相信很多人都玩过。没玩过也没关系,下面我给大家介绍一下游戏规则:在一个棋盘中,放了很多的棋子。如果某两个相同的棋子,可以通过一条线连起来(这条线不能经过其它棋子),而且线的转折次数不超过两次,那么这两个棋子就可以在棋盘上消去。不好意思,由于我以前没有玩过连连看,咨询了同学的意见,连线不能从外面绕过去的,但事实上这是错的。现在已经酿成大祸,就只能...原创 2017-09-27 22:39:33 · 307 阅读 · 0 评论 -
CodeForces - 330D Biridian Forest(BFS+思维)
CodeForces - 330D Biridian Forest题意:MIkemon从S出发,要走到E,中途可能会遇到breeder,与breeder相遇时就要发生一场battle,一个格子可能有多个breeder,此时Mikemon就会与么以一个breeder发生一场battle,Mikemo提前设计好走出森林的路线,假设所有的breeder已经知道Mikemon走的路线,并且主动与Mikem...原创 2017-09-27 09:23:53 · 507 阅读 · 0 评论 -
CodeForces - 540C Ice Cave(BFS)
CodeForces - 540C Ice CaveYou play a computer game. Your character stands on some level of a multilevel ice cave. In order to move on forward, you need to descend one level lower and the only way to d...原创 2017-09-20 15:38:51 · 391 阅读 · 0 评论 -
CodeForces - 742C Arpa's loud Owf and Mehrdad's evil plan(dfs+最小公倍数)
CodeForces - 742C Arpa's loud Owf and Mehrdad's evil pla 题意:问题可转化为 给定一个有向图,相邻两点的距离是1,求一个最小的 t,使从任意一点x走k步到y,y也能走k步到x,t不存在则输出-1 思路:有向图找环问题,如果存在 t,则有向图肯定由若干个环组成,如果环的长度k为奇数,那么需要k步,如果环的长度为偶数,那么需要...原创 2017-09-15 13:31:57 · 511 阅读 · 0 评论 -
CodeForces - 735A Ostap and Grasshopper (BFS)
CodeForces - 735A Ostap and Grasshopper (BFS)简单题,用的广搜 #include <stdio.h>#include <iostream>#include <algorithm>#include <string.h>#include <math.h> #include <s...原创 2017-09-01 11:28:04 · 271 阅读 · 0 评论 -
HDU1026 Ignatius and the Princess I(广搜与优先队列)
Ignatius and the Princess ITime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 19931 Accepted Submission(s): 6502Special JudgeProblem Description...原创 2017-10-16 22:14:10 · 306 阅读 · 0 评论 -
最短路算法模板
首先是Dijkstra算法,Dijkstra算法适用于边权为正的情况,它可用于计算正权图上的单源最短路,即从单个源点出发,到所有结点的最短路,该算法同时适用于有向图和无向图。给出代码的时间复杂度为O(mlogn),m为边的数目,n为点的数目。struct Edge{ int from,to,dist; //从点from到to点距离dist Edge(int u,int v,int d):fr...原创 2018-04-13 20:28:24 · 250 阅读 · 0 评论 -
ZOJ - 3204 Connect them (最小生成树)
题意:输出字母序最小的最小生成树思路:对边按照cost u v排序之后,求最小生成树,然后在对u v排序输出#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <algorithm>#include <stack&g...原创 2018-04-20 19:06:56 · 224 阅读 · 0 评论 -
ZOJ - 3497 Mistwald(离散数学)
题意:一张n*m的图,告诉你每一个点可以到达哪4个点,然后给出一个p,问从(1,1)出发P步之后,是否能到达(n,m),如果一定能达,输出true,如果可能到达输出maybe,如果不能到达,输出false思路:我们可以给每一个点编号0 - n * m - 1,再建立一个邻接矩阵A,这样就是求0是否能到达n * m - 1,离散数学曾学过这样一个性质,A的p方得到的邻接矩阵,aij表示从i到j有多少...原创 2018-04-21 19:17:56 · 268 阅读 · 0 评论 -
UVA- Ancient Messages 1103(dfs)
题目链接:https://cn.vjudge.net/problem/UVA-1103原创 2018-05-12 11:02:15 · 171 阅读 · 0 评论 -
ZOJ - 3865 Superbot (广搜)
SuperbotTime Limit: 2 Seconds Memory Limit: 65536 KBSuperbot is an interesting game which you need to control the robot on an N*M grid map.As you see, it's just a simple game: there is a control ...原创 2018-04-27 16:12:30 · 210 阅读 · 0 评论 -
关于二分匹配的几道简单题
最近重新学习了二分匹配的算法,并趁热打铁做了几道简单的题。这个博客讲的二分匹配的算法比较通俗易懂,https://blog.csdn.net/dark_scope/article/details/8880547HDU 1150把每一个任务在两种机器下的模式看作一条边,建图之后求最小顶点覆盖集(用最少的点,使每一条边都与其中一个点相关联),而最小顶点覆盖集=最大匹配,此题在输入的时候把模式为0的去掉...原创 2018-05-28 23:44:30 · 246 阅读 · 0 评论 -
HDU 6201 transaction (spfa最长路) 2017 ACM/ICPC Asia Regional Shenyang Online
transaction transaction transactionTime Limit: 4000/2000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Others)Total Submission(s): 2127 Accepted Submission(s): 980Problem DescriptionKeluk...原创 2018-06-05 14:26:28 · 169 阅读 · 0 评论 -
HDU 5093 Battle ships (二分图匹配)
Battle shipsTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1857 Accepted Submission(s): 686 Problem DescriptionDear contestant, now ...原创 2018-07-16 20:34:33 · 518 阅读 · 0 评论 -
HDU 5094 Maze(状态压缩+BFS)
MazeTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 100000/100000 K (Java/Others)Total Submission(s): 1729 Accepted Submission(s): 597 Problem DescriptionThis story happened on the ...原创 2018-07-17 13:12:22 · 235 阅读 · 0 评论 -
HDU 6187 Destroy Walls(最小生成树)
Destroy WallsTime Limit: 8000/4000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Others)Total Submission(s): 831 Accepted Submission(s): 358Problem Description Long times ago, there are b...原创 2018-07-14 19:05:24 · 247 阅读 · 0 评论 -
HDU - 4725 The Shortest Path in Nya Graph (最短路)
The Shortest Path in Nya GraphTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 10675 Accepted Submission(s): 2330 Problem DescriptionT...原创 2018-07-25 21:47:35 · 223 阅读 · 0 评论 -
POJ - 3694 Network(割边+LCA)
NetworkTime Limit: 5000MS Memory Limit: 65536KTotal Submissions: 11971 Accepted: 4406DescriptionA network administrator manages a large network. The network consists of N computers and M links between...原创 2018-07-15 11:42:26 · 181 阅读 · 0 评论