
图论
文章平均质量分 81
i-unique
擅长各种姿势划水
展开
-
游历魔法王国(牛客网 网易2018校招题 图论)
链接:https://www.nowcoder.com/questionTerminal/f58859adc39f4edc9cd8e40ba4160339来源:牛客网魔法王国一共有n个城市,编号为0~n-1号,n个城市之间的道路连接起来恰好构成一棵树。小易现在在0号城市,每次行动小易会从当前所在的城市走到与其相邻的一个城市,小易最多能行动L次。如果小易到达过某个城市就视为小易游历过这个城市...原创 2018-09-10 14:25:07 · 430 阅读 · 0 评论 -
HDU 1532 Drainage Ditches(最大流+EK算法模板题)
Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover patch. This means that the clover is covered by water for awhile and takes quite a long time to regrow. Thus, Farmer John has built a set of drainage ditches so that Be原创 2017-09-03 20:29:58 · 590 阅读 · 0 评论 -
关于数据结构和图论的一些入门攻略
我是负责我们队数据结构和图论的,在集训队做了一个多月的题,应该算是图论和数据结构入门了吧,这里我推荐一些图论和数据结构的算法学习顺序(我的见解),如果对这一方面有兴趣的可以看一看。(日常菜的抠脚不想去刷题)原创 2017-08-12 19:32:38 · 2179 阅读 · 1 评论 -
CCPC网赛 Friend-Graph(图论+模拟+输入外挂)
It is well known that small groups are not conducive of the development of a team. Therefore, there shouldn’t be any small groups in a good team. In a team with n members,if there are three or more members are not friends with each other or there are thre原创 2017-08-19 18:13:14 · 450 阅读 · 0 评论 -
HDU 2389 Rain on your Parade(二分匹配+Hopcroft-Carp算法模板题)
You’re giving a party in the garden of your villa by the sea. The party is a huge success, and everyone is here. It’s a warm, sunny evening, and a soothing wind sends fresh, salty air from the sea. The evening is progressing just as you had imagined. It co原创 2017-08-10 10:26:23 · 1049 阅读 · 0 评论 -
HDU 1281 棋盘游戏(二分图匹配+匈牙利算法+模拟)
小希和Gardon在玩一个游戏:对一个N*M的棋盘,在格子里放尽量多的一些国际象棋里面的“车”,并且使得他们不能互相攻击,这当然很简单,但是Gardon限制了只有某些格子才可以放,小希还是很轻松的解决了这个问题(见下图)注意不能放车的地方不影响车的互相攻击。 所以现在Gardon想让小希来解决一个更难的问题,在保证尽量多的“车”的前提下,棋盘里有些格子是可以避开的,也就是说,不在这些格子上放车,也可以保证尽量多的“车”被放下。但是某些格子若不放子,就无法保证放尽量多的“车”,这样的格子被称做重要点。Gar原创 2017-08-18 10:33:48 · 288 阅读 · 0 评论 -
HDU 1179 Ollivanders: Makers of Fine Wands since 382 BC.(二分图匹配+匈牙利算法)
In Diagon Alley ,there is only one Wand-seller,peeling gold letters over the door read Ollivanders: Makers of Fine Wands since 382 BC.A single wand lay on a faded purple cushion in the dusty window. A tinkling bell rang somewhere in the depths of the shop原创 2017-08-18 09:16:17 · 336 阅读 · 0 评论 -
POJ 1861 Network(最小生成树+克鲁斯卡尔)
Andrew is working as system administrator and is planning to establish a new network in his company. There will be N hubs in the company, they can be connected to each other using cables. Since each worker of the company must have access to the whole netwo原创 2017-08-17 21:16:18 · 265 阅读 · 0 评论 -
二分图匹配的学习(博客收集向)
二分图匹配关于入门知识的博客收集以及匈牙利算法,Hopcroft-Carp算法算法模板原创 2017-08-07 15:53:28 · 462 阅读 · 0 评论 -
WUST 1945 局域网(最小生成树入门+克鲁斯卡尔算法)
某个局域网内有n(n<=100)台计算机,由于搭建局域网时工作人员的疏忽,现在局域网内的连接形成了回路,我们知道如果局域网形成回路那么数据将不停的在回路内传输,造成网络卡的现象。因为连接计算机的网线本身不同,所以有一些连线不是很畅通,我们用f(i,j)表示i,j之间连接的畅通程度(f(i,j)<=1000),f(i,j)值越小表示i,j之间连接越通畅,f(i,j)为0表示i,j之间无网线连接。现在我们需要解决回路问题,我们将除去一些连线,使得网络中没有回路,并且被除去网线的Σf(i,j)最大,请求出这个最大原创 2017-07-09 12:46:48 · 700 阅读 · 0 评论 -
WUST 1935 香甜的黄油(最短路径+SPFA算法)
农夫John发现做出全威斯康辛州最甜的黄油的方法:糖。把糖放在一片牧场上,他知道N(1<=N<=500)只奶牛会过来舔它,这样就能做出能卖好价钱的超甜黄油。当然,他将付出额外的费用在奶牛上。 农夫John很狡猾。像以前的巴甫洛夫,他知道他可以训练这些奶牛,让它们在听到铃声时去一个特定的牧场。他打算将糖放在那里然后下午发出铃声,以至他可以在晚上挤奶。农夫John知道每只奶牛都在各自喜欢的牧场(一个牧场不一定只有一头牛)。给出各头牛在的牧场和牧场间的路线,找出使所有牛到达的路程和最短的牧场(他将把糖放在那)原创 2017-07-10 22:07:55 · 611 阅读 · 0 评论 -
HDU 3371 Connect the Cities (最小生成树+克鲁斯卡尔算法)
In 2100, since the sea level rise, most of the cities disappear. Though some survived cities are still connected with others, but most of them become disconnected. The government wants to build some roads to connect all of these cities again, but they don’原创 2017-07-11 19:45:34 · 387 阅读 · 0 评论 -
POJ 1459 Power Network(最大流+EK算法邻接矩阵写法)
A power network consists of nodes (power stations, consumers and dispatchers) connected by power transport lines. A node u may be supplied with an amount s(u) >= 0 of power, may produce an amount 0 <= p(u) <= p max(u) of power, may consume an amount 0 <= c原创 2017-09-04 10:53:13 · 488 阅读 · 0 评论 -
POJ 1459 Power Network(最大流+dinic算法模板)
A power network consists of nodes (power stations, consumers and dispatchers) connected by power transport lines. A node u may be supplied with an amount s(u) >= 0 of power, may produce an amount 0 <= p(u) <= p max(u) of power, may consume an amount 0 <= c原创 2017-09-04 16:53:33 · 424 阅读 · 0 评论 -
网络流题集【转】
博客原文:http://blog.youkuaiyun.com/shahdza/article/details/7779537最近搞网络流。。觉得这篇博客总结的题集感觉很有用,mark转载下来【HDU】1532Drainage Ditches(入门) [最大流]3549 Flow Problem(入门) [最大流]3572 Task Schedule(基础) [最大流转载 2017-09-04 19:40:20 · 571 阅读 · 0 评论 -
URAL 1056 Computer Net (图论+bfs)
Computer net is created by consecutive computer plug-up to one that has already been connected to the net. Each new computer gets an ordinal number, but the protocol contains the number of its parent computer in the net. Thus, protocol consists of several原创 2017-12-03 22:35:14 · 328 阅读 · 0 评论 -
CodeForces 337D Book of Evil(双向dfs)
Paladin Manao caught the trail of the ancient Book of Evil in a swampy area. This area contains n settlements numbered from 1 to n. Moving through the swamp is very difficult, so people tramped exactly n - 1 paths. Each of these paths connects some pair of原创 2017-10-29 19:44:14 · 398 阅读 · 0 评论 -
网络流基础篇——Edmond-Karp算法
网络流的相关定义:源点:有n个点,有m条有向边,有一个点很特殊,只出不进,叫做源点。汇点:另一个点也很特殊,只进不出,叫做汇点。容量和流量:每条有向边上有两个量,容量和流量,从i到j的容量通常用c[i,j]表示,流量则通常是f[i,j].通常可以把这些边想象成道路,流量就是这条道路的车流量,容量就是道路可承受的最大的车流量。很显然的,流量<=容量。而对于每个不是源点和汇点的点来说,可以类比的想象成没有存储功能的货物的中转站,所有“进入”他们的流量和等于所有从他本身“出去”的流量。最大流:把源点转载 2017-08-31 09:36:54 · 656 阅读 · 0 评论 -
CodeForces125E MST Company(根限度为k的最小生成树+二分)
The MST (Meaningless State Team) company won another tender for an important state reform in Berland.There are n cities in Berland, some pairs of the cities are connected by roads. Each road has its price. One can move along any road in any direction. The原创 2017-09-03 15:25:37 · 1022 阅读 · 0 评论 -
2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛 A. Banana(连通性水题)
Bananas are the favoured food of monkeys.In the forest, there is a Banana Company that provides bananas from different places.The company has two lists.The first list records the types of bananas preferred by different monkeys, and the second one rec原创 2017-09-09 16:58:50 · 434 阅读 · 0 评论 -
2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛 F. Islands(有向图加边变成一个强连通图)
On the mysterious continent of Tamriel, there is a great empire founded by human.To develope the trade, the East Empire Company is set up to transport goods from place to place.Recently, the company wants to start their business in Solstheim, which is原创 2017-09-09 16:59:49 · 1386 阅读 · 0 评论 -
HDU 6201 transaction transaction transaction(SPFA算法求最长路径)
Kelukin is a businessman. Every day, he travels around cities to do some business. On August 17th, in memory of a great man, citizens will read a book named "the Man Who Changed China". Of course, Kelukin wouldn't miss this chance to make money, but he doe原创 2017-09-14 20:52:00 · 420 阅读 · 0 评论 -
模板总结
属于自己的模板。。。比赛防忘记赛前复习向原创 2017-07-24 10:25:30 · 1561 阅读 · 1 评论 -
hdu 6184 Counting Stars(求无向图三元环)
Little A is an astronomy lover, and he has found that the sky was so beautiful! So he is counting stars now! There are n stars in the sky, and little A has connected them by m non-directional edges. It is guranteed that no edges connect one star with原创 2017-09-05 21:12:42 · 840 阅读 · 2 评论 -
HDU 6187 Destroy Walls(最大生成树)
Long times ago, there are beautiful historic walls in the city. These walls divide the city into many parts of area. Since it was not convenient, the new king wants to destroy some of these walls, so he can arrive anywhere from his castle. We assume that原创 2017-09-05 19:46:42 · 509 阅读 · 0 评论 -
HDU 3549 Flow Problem(最大流+EK邻接表||邻接矩阵||dinic算法模板比较)
Network flow is a well-known difficult problem for ACMers. Given a graph, your task is to find out the maximum flow for the weighted directed graph.原创 2017-09-04 19:48:33 · 910 阅读 · 0 评论 -
WUST 一笔画(图论知识之欧拉路)
对给定的一个无向图,判断能否一笔画出。若能,输出一笔画的先后顺序,否则输出“No Solution!”所谓一笔画出,即每条边仅走一次,每个顶点可以多次经过。输出字典序最小的一笔画顺序。原创 2017-07-13 08:25:50 · 696 阅读 · 1 评论 -
WUST 1927 信使(最短路之弗洛伊德算法)
相信都知道这个算法是最短路里面最好写的算法了,也是求全图任意两个顶点间最短路的最好算法,临接矩阵保存路径,然后三重循环,时间复杂度是o(n^3),这么高的复杂度使得他几乎不出现在比赛里面,一般只会出现在娱乐赛里面吧,不过还是要掌握的原创 2017-07-13 19:59:59 · 1780 阅读 · 0 评论 -
WUST 1946 繁忙的都市(最小生成树+克鲁斯卡尔算法)
城市C是一个非常繁忙的大都市,城市中的道路十分的拥挤,于是市长决定对其中的道路进行改造。城市C的道路是这样分布的:城市中有n个交叉路口,有些交叉路口之间有道路相连,两个交叉路口之间最多有一条道路相连接。这些道路是双向的,且把所有的交叉路口直接或间接的连接起来了。每条道路都有一个分值,分值越小表示这个道路越繁忙,越需要进行改造。但是市政府的资金有限,市长希望进行改造的道路越少越好,于是他提出下面的要求:改造的那些道路能够把所有的交叉路口直接或间接的连通起来。在满足要求1的情况下,改造的道路尽量少。在满足原创 2017-07-15 21:20:05 · 443 阅读 · 0 评论 -
HDU 4160 Dolls(二分图匹配+匈牙利算法+最小路径覆盖)
Do you remember the box of Matryoshka dolls last week? Adam just got another box of dolls from Matryona. This time, the dolls have different shapes and sizes: some are skinny, some are fat, and some look as though they were attened. Specifically, doll i ca原创 2017-08-08 10:18:46 · 528 阅读 · 0 评论 -
POJ 3522 Slim Span(生成树+克鲁斯卡尔)
Given an undirected weighted graph G, you should find one of spanning trees specified as follows.The graph G is an ordered pair (V, E), where V is a set of vertices {v1, v2, …, vn} and E is a set of undirected edges {e1, e2, …, em}. Each edge e ∈ E has it原创 2017-08-08 18:56:06 · 418 阅读 · 0 评论 -
HDU 1528 Card Game Cheater(二分图匹配+匈牙利算法+模拟)
Adam and Eve play a card game using a regular deck of 52 cards. The rules are simple. The players sit on opposite sides of a table, facing each other. Each player gets k cards from the deck and, after looking at them, places the cards face down in a row on原创 2017-08-08 19:14:41 · 504 阅读 · 0 评论 -
UVA 12168 Cat vs. Dog(二分图匹配+匈牙利算法+最大独立集+数据转化)
The latest reality show has hit the TV: ``Cat vs. Dog''. In this show, a bunch of cats and dogs compete for the very prestigious Best Pet Ever title. In each episode, the cats and dogs get to show themselves off, after which the viewers vote on which pets原创 2017-08-09 19:57:26 · 669 阅读 · 0 评论 -
POJ 3692 Kindergarten(最大匹配+匈牙利算法+补图思想)
In a kindergarten, there are a lot of kids. All girls of the kids know each other and all boys also know each other. In addition to that, some girls and boys know each other. Now the teachers want to pick some kids to play a game, which need that all playe原创 2017-08-09 20:44:39 · 464 阅读 · 0 评论 -
HDU 1150 Machine Schedule(二分匹配+匈牙利算法)
As we all know, machine scheduling is a very classical problem in computer science and has been studied for a very long history. Scheduling problems differ widely in the nature of the constraints that must be satisfied and the type of schedule desired. Her原创 2017-08-10 20:54:27 · 287 阅读 · 0 评论 -
POJ 2446 Chessboard(二维转一维+二分匹配+匈牙利算法)
Alice and Bob often play games on chessboard. One day, Alice draws a board with size M * N. She wants Bob to use a lot of cards with size 1 * 2 to cover the board. However, she thinks it too easy to bob, so she makes some holes on the board (as shown in th原创 2017-08-11 16:18:52 · 465 阅读 · 0 评论 -
HDU 1068 Girls and Boys(二分图匹配+最大独立集+匈牙利算法)
the second year of the university somebody started a study on the romantic relations between the students. The relation “romantically involved” is defined between one girl and one boy. For the study reasons it is necessary to find out the maximum set satis原创 2017-08-15 09:03:35 · 653 阅读 · 0 评论 -
POJ 1422 Air Raid(二分图匹配+最小路径覆盖+匈牙利算法)
Consider a town where all the streets are one-way and each street leads from one intersection to another. It is also known that starting from an intersection and walking through town's streets you can never reach the same intersection i.e. the town's stree原创 2017-08-15 20:58:37 · 354 阅读 · 0 评论 -
spfa算法的初步理解
首先这是个单源最短路径的算法,要用到队列,类似于bfs的思想,先用邻接矩阵p[n][m]保存路径,先将遍历数vis[i]组置为0,初始化dis[i]表示已知的初始点到点的距离,dis[起始点]为0,其他的置为INF(最大值),先将起始点的情况放入队列中,vis[起点]=1;当队列不为空时,先取出队头,遍历所有节点,如果存在dis[当前节点]>dis[k]+p[k][当前],那么将标号k放入队列,将vis[k]=1;循环结束后将vis[当前]=0,继续直到队列为空例题:另外一篇博客:http://blog原创 2017-06-03 11:43:36 · 598 阅读 · 0 评论 -
最小生成树之prim算法(优先队列优化)
prim算法适合稠密图,即边数较多而点较少的情况,时间复杂度为n^2,堆优化的情况下,如果点数为m,边数为n,可以达到nlongm,我还是习惯用优先队列写这个算法,思想很简单,就是每次寻找一条由已加入集合的点和与它们相邻的没加入集合的点的权值最小边(有点绕理解下),进行n-1次就找出来了,也是贪心的思想,实现就是随便找一个初始节点,然后建一个最小堆(边小的先pop出来),把该节点的vis值置为1,遍历该节点相邻的节点,如果没有被vis标记过,就加入边到堆中,扫完了以后处理堆中数据,如果弹出的边被标记过就po原创 2017-07-13 09:31:00 · 7710 阅读 · 1 评论