
图论——二分图
Alex_McAvoy
想要成为渔夫的猎手
展开
-
图论 —— 二分图
【概述】二分图又称作偶图,是图论中的一种特殊模型。设 G=(V,E) 是一无向图,若顶点 V 可分割为两个互不相交的子集 (A,B),且图中的每条边(i,j)所关联的两个顶点 i 和 j 分属这两个不同的顶点集 (i ∈A,j ∈B),则称图 G 为一二分图。其充要条件是:图 G 中至少存在两个点,且图中所有回路的长度均为偶数。简单来说,就是顶点集 V 可分割为两个互不相交的子...原创 2019-03-16 17:22:23 · 22937 阅读 · 4 评论 -
图论 —— 二分图 —— 二分图判定
二分图的判定问题比较少见,简单来说,就是对于给定的图,判断图是否为二分图。可以把每个节点着以黑色和白色之一,使得每条边的两个端点颜色不同,不难发现,对于一个当且仅当每个连通分量都是二分图,因此我们只考虑无向连通图。无向图 G 为二分图的充分必要条件:G 至少有两个顶点,且其所有回路的长度均为偶数。int n;//节点数vector<int> G[N];//G[i]表示i...转载 2019-02-20 22:45:48 · 3133 阅读 · 1 评论 -
图论 —— 二分图 —— 匈牙利算法
【基本概念】1.交替路从一个未匹配点出发,依次经过 非匹配边、匹配边、非匹配边… 形成的路径2.增广路定义:设 M 为二分图 G 已匹配边的集合,若 P 是图 G 中一条连通两个未匹配点的路径(起点在 X/Y部,终点在 Y/X 部),且属 M 的边(匹配边)与不属 M 的边(非匹配边)在 P 上交替出现,则称 P 为相对 M 的一条增广路径。由于增广路的第一条边是没有参与匹配...原创 2019-02-20 22:49:55 · 3456 阅读 · 0 评论 -
图论 —— 二分图 —— KM 算法
【原理】KM 算法是用于求带权二分图的最优匹配的算法,其时间复杂度为 O(N^3)。1.首先选择顶点数较少的为 X 部(左点集),初始时对 X 部的每一个顶点设置顶标,顶标的值为该点关联的最大边的权值,Y 部(右点集)的顶点顶标为 0。2.对于 X 部中的每个顶点,在相等子图中利用匈牙利算法找一条增广路径,如果没有找到,则修改顶标,扩大相等子图,继续找增广路径。3.当 X 部的每个...转载 2019-02-20 22:52:18 · 3428 阅读 · 0 评论 -
Uncle Tom's Inherited Land(HDU-1507)
Problem DescriptionYour old uncle Tom inherited a piece of land from his great-great-uncle. Originally, the property had been in the shape of a rectangle. A long time ago, however, his great-great-...原创 2019-03-13 08:24:22 · 732 阅读 · 0 评论 -
Going Home(POJ-2195)
Problem DescriptionOn a grid map there are n little men and n houses. In each unit time, every little man can move one unit step, either horizontally, or vertically, to an adjacent point. For each ...原创 2018-12-06 21:49:05 · 617 阅读 · 0 评论 -
Interesting Housing Problem(HDU-2426)
Problem DescriptionFor any school, it is hard to find a feasible accommodation plan with every student assigned to a suitable apartment while keeping everyone happy, let alone an optimal one. Recen...原创 2018-12-06 22:11:36 · 391 阅读 · 0 评论 -
Special Fish(HDU-3395)
Problem DescriptionThere is a kind of special fish in the East Lake where is closed to campus of Wuhan University. It’s hard to say which gender of those fish are, because every fish believes itsel...原创 2018-12-06 22:32:14 · 425 阅读 · 0 评论 -
Chocolate(HDU-2282)
Problem DescriptionLethe loves eating chocolates very much. In Lethe's birthday, her good friend echo brings N boxes to her, and makes the boxes on the circle. Furthermore, echo tells Lethe that th...原创 2018-12-07 16:44:53 · 488 阅读 · 0 评论 -
Assignment(HDU-2853)
Problem DescriptionLast year a terrible earthquake attacked Sichuan province. About 300,000 PLA soldiers attended the rescue, also ALPCs. Our mission is to solve difficulty problems to optimization...原创 2018-12-10 13:09:40 · 349 阅读 · 0 评论 -
My Brute(HDU-3315)
Problem DescriptionSeaco is a beautiful girl and likes play a game called “My Brute”. Before Valentine’s Day, starvae and xingxing ask seaco if she wants to spend the Valentine’s Day with them, but...原创 2018-12-10 13:17:50 · 399 阅读 · 0 评论 -
Battle ships(HDU-5093)
Problem DescriptionDear contestant, now you are an excellent navy commander, who is responsible of a tough mission currently.Your fleet unfortunately encountered an enemy fleet near the South Po...原创 2019-01-18 12:07:01 · 388 阅读 · 0 评论 -
Factors and Multiples(LightOJ-1149)
Problem DescriptionYou will be given two sets of integers. Let's call them set A and set B. Set A contains n elements and set B contains m elements. You have to remove k1 elements from set A and k2...原创 2019-01-23 20:48:28 · 349 阅读 · 0 评论 -
Arbiter(HDU-3118)
Problem DescriptionArbiter is a kind of starship in the StarCraft science-fiction series. The Arbiter-class starship is a Protoss warship specializing in providing psychic support. Arbiters were cr...原创 2019-03-13 20:45:55 · 468 阅读 · 0 评论 -
Cat vs. Dog(HDU-2768)
Problem DescriptionThe 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 an...原创 2019-03-13 09:31:28 · 673 阅读 · 0 评论 -
Matrix(HDU-2119)
Problem DescriptionGive you a matrix(only contains 0 or 1),every time you can select a row or a column and delete all the '1' in this row or this column .Your task is to give out the minimum tim...原创 2019-03-13 09:25:43 · 331 阅读 · 0 评论 -
Fire Net(HDU-1045)
Problem DescriptionSuppose that we have a square city with straight streets. A map of a city is a square board with n rows and n columns, each representing a street or a piece of wall.A blockhou...原创 2019-03-13 21:08:26 · 694 阅读 · 0 评论 -
Girls and Boys(HDU-1068)
Problem DescriptionIn 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...原创 2019-03-11 21:34:37 · 2737 阅读 · 0 评论 -
Machine Schedule(HDU-1150)
Problem DescriptionAs 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 o...原创 2019-03-12 14:52:07 · 603 阅读 · 0 评论 -
Ollivanders: Makers of Fine Wands since(HDU-1179)
Problem DescriptionIn 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 ...原创 2019-03-12 15:31:35 · 463 阅读 · 0 评论 -
奔小康赚大钱(HDU-2255)
Problem Description传说在遥远的地方有一个非常富裕的村落,有一天,村长决定进行制度改革:重新分配房子。这可是一件大事,关系到人民的住房问题啊。村里共有n间房间,刚好有n家老百姓,考虑到每家都要有房住(如果有老百姓没房子住的话,容易引起不安定因素),每家必须分配到一间房子且只能得到一间房子。另一方面,村长和另外的村领导希望得到最大的效益,这样村里的机构才会有钱.由于老百姓...原创 2018-12-06 15:18:38 · 584 阅读 · 0 评论 -
A new Graph Game( HDU-3435)
Problem DescriptionAn undirected graph is a graph in which the nodes are connected by undirected arcs. An undirected arc is an edge that has no arrow. Both ends of an undirected arc are equivalent-...原创 2018-12-08 20:52:32 · 356 阅读 · 0 评论 -
Cyclic Tour(HDU-1853)
Problem DescriptionThere are N cities in our country, and M one-way roads connecting them. Now Little Tom wants to make several cyclic tours, which satisfy that, each cycle contain at least two cit...原创 2018-12-08 19:49:39 · 325 阅读 · 0 评论 -
The Perfect Stall(POJ-1274)
Problem DescriptionFarmer John completed his new barn just last week, complete with all the latest milking technology. Unfortunately, due to engineering problems, all the stalls in the new barn are...原创 2018-11-26 23:36:20 · 507 阅读 · 0 评论 -
COURSES(POJ-1469)
Problem DescriptionConsider a group of N students and P courses. Each student visits zero, one or more than one courses. Your task is to determine whether it is possible to form a committee of exac...原创 2018-11-26 23:26:25 · 697 阅读 · 0 评论 -
Girls and Boys(POJ-1466)
Problem DescriptionIn 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...原创 2018-11-29 23:59:14 · 1041 阅读 · 0 评论 -
Cat VS Dog(HDU-3829)
Problem DescriptionThe zoo have N cats and M dogs, today there are P children visiting the zoo, each child has a like-animal and a dislike-animal, if the child's like-animal is a cat, then his/hers...原创 2018-11-29 23:18:36 · 651 阅读 · 0 评论 -
Guardian of Decency(POJ-2771)
Problem DescriptionFrank N. Stein is a very conservative high-school teacher. He wants to take some of his students on an excursion, but he is afraid that some of them might become couples. While y...原创 2018-11-29 22:42:49 · 18477 阅读 · 0 评论 -
Kindergarten(POJ-3692)
Problem DescriptionIn 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...原创 2018-11-29 22:09:28 · 413 阅读 · 0 评论 -
Jimmy’s Assignment(HDU 1845)
Problem DescriptionJimmy is studying Advanced Graph Algorithms at his university. His most recent assignment is to find a maximum matching in a special kind of graph. This graph is undirected, has ...原创 2018-11-28 21:27:52 · 347 阅读 · 0 评论 -
棋盘游戏(HDU-1281)
Problem Description小希和Gardon在玩一个游戏:对一个N*M的棋盘,在格子里放尽量多的一些国际象棋里面的“车”,并且使得他们不能互相攻击,这当然很简单,但是Gardon限制了只有某些格子才可以放,小希还是很轻松的解决了这个问题(见下图)注意不能放车的地方不影响车的互相攻击。所以现在Gardon想让小希来解决一个更难的问题,在保证尽量多的“车”的前提下,棋盘里有些格子...原创 2018-11-28 21:20:12 · 1664 阅读 · 0 评论 -
Selecting Courses(POJ-2239)
Problem DescriptionIt is well known that it is not easy to select courses in the college, for there is usually conflict among the time of the courses. Li Ming is a student who loves study every muc...原创 2018-11-26 23:49:00 · 942 阅读 · 0 评论 -
Gopher II(POJ-2536 )
Problem DescriptionThe gopher family, having averted the canine threat, must face a new predator.The are n gophers and m gopher holes, each at distinct (x, y) coordinates. A hawk arrives and if ...原创 2018-11-27 00:02:33 · 326 阅读 · 0 评论 -
Mining Station on the Sea(HDU-2448)
Problem DescriptionThe ocean is a treasure house of resources and the development of human society comes to depend more and more on it. In order to develop and utilize marine resources, it is neces...原创 2018-12-08 19:23:41 · 400 阅读 · 0 评论 -
Card Game Cheater(HDU-1528)
Problem DescriptionAdam 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 fr...原创 2019-03-13 08:59:27 · 508 阅读 · 0 评论 -
Machine Schedule(POJ-1325)
Problem DescriptionAs 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 o...原创 2018-12-02 19:17:44 · 332 阅读 · 0 评论 -
50 years, 50 colors(HDU-1498)
Problem DescriptionOn Octorber 21st, HDU 50-year-celebration, 50-color balloons floating around the campus, it's so nice, isn't it? To celebrate this meaningful day, the ACM team of HDU hold some f...原创 2018-12-02 19:00:24 · 420 阅读 · 0 评论 -
Strategic Game(HDU-1054)
Problem DescriptionBob enjoys playing computer games, especially strategic games, but sometimes he cannot find the solution fast enough and then he is very sad. Now he has the following problem. He...原创 2018-12-02 18:30:28 · 377 阅读 · 0 评论 -
Asteroids(POJ-3041)
Problem DescriptionBessie wants to navigate her spaceship through a dangerous asteroid field in the shape of an N x N grid (1 <= N <= 500). The grid contains K asteroids (1 <= K <= 10,0...原创 2018-12-02 18:12:24 · 451 阅读 · 0 评论 -
The Accomodation of Students(HDU-2444 )
Problem DescriptionThere are a group of students. Some of them may know each other, while others don't. For example, A and B know each other, B and C know each other. But this may not imply that A ...原创 2018-11-27 00:29:13 · 612 阅读 · 0 评论