
——图论——
文章平均质量分 73
STILLxjy
不要让任何人打乱你生活的节奏
展开
-
(LeetCode 947)移除最多的同行或同列石头 [并查集 + 求解连通分量的个数]
947. 移除最多的同行或同列石头在二维平面上,我们将石头放置在一些整数坐标点上。每个坐标点上最多只能有一块石头。现在,move 操作将会移除与网格上的某一块石头共享一列或一行的一块石头。我们最多能执行多少次 move 操作?示例 1:输入:stones = [[0,0],[0,1],[1,0],[1,2],[2,1],[2,2]]输出:5示例 2:输入:stones = [[0,...原创 2019-02-27 20:19:27 · 662 阅读 · 0 评论 -
(POJ 3259)Wormholes 判断负环 bellman_ford 或者 spfa
Wormholes Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 45772 Accepted: 16904 DescriptionWhile exploring his many farms, Farmer John has discovered a number of amazing wormh原创 2016-10-28 16:54:42 · 492 阅读 · 0 评论 -
(2016 弱校联盟十一专场10.3) Similarity of Subtrees DFS + hash
题目链接 https://acm.bnu.edu.cn/v3/problem_show.php?pid=52310problem description Define the depth of a node in a rooted tree by applying the following rules recursively: • The depth of a root node原创 2016-10-27 15:39:06 · 602 阅读 · 0 评论 -
(2016弱小联盟十一专场10.3) Help the Princess! BFS
题目连接: https://acm.bnu.edu.cn/v3/statments/jag2016.pdf分析:直接判断‘%’到‘@’和最近的‘$’的距离,如果 ‘%’到‘@’小于%’到最近的‘$’的距离则输出YES否则输出NOAC代码:#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#in原创 2016-10-26 22:59:53 · 438 阅读 · 0 评论 -
Barricade bfs + 最小割(最大流)---最短路上求最大流模板
BarricadeTime Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 1129 Accepted Submission(s): 345Problem Description The empire is under attack aga原创 2016-09-28 17:49:19 · 511 阅读 · 0 评论 -
(POJ1149)PIGS(建图+EK模板,Ford-fulkerson)
PIGS Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 19792 Accepted: 9062 DescriptionMirko works on a pig farm that consists of M locked pig-houses and Mirko can’t unlock any原创 2016-07-21 16:31:26 · 654 阅读 · 0 评论 -
初识网络流(一般增广路算法-Ford-Fulkerson)
这两天看了看求最大网络流的问题。着实有点费脑子。不过还好还是很有收获的。 在这里写的是关于通过找增广路求最大流的算法Ford-Fulkerson。算法的思路是通过BFS利用标记来找增广路。 具体过程如下: 从一个可行流出发(可以是零流),进入标号过程和调整过程: 1:标号过程: 在标号过程中,容量网络中的顶点可以分为三类: (1)未标号顶点 (2)已标号,未检查相邻顶点 (3)已标号原创 2016-07-21 16:02:35 · 4285 阅读 · 0 评论 -
(NYoj 284)坦克大战--裸BFS ,优先队列
坦克大战 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 Many of us had played the game “Battle city” in our childhood, and some people (like me) even often play it on computer now. What we are discussing is原创 2016-07-30 12:43:06 · 660 阅读 · 0 评论 -
(POJ 3281)Dining --最大流,匹配建图,Dinic
Dining Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10755 Accepted: 4930Description Cows are such finicky eaters. Each cow has a preference for certain foods and drinks, an原创 2016-07-30 12:34:29 · 546 阅读 · 0 评论 -
Domino Effect(dijkstra)
Domino Effect Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10482 Accepted: 2596 DescriptionDid you know that you can use domino bones for other things besides playing Domin原创 2016-07-15 10:14:18 · 670 阅读 · 1 评论 -
Arbitrage(bellman,最长路径)
Arbitrage Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20181 Accepted: 8574 DescriptionArbitrage is the use of discrepancies in currency exchange rates to transform one uni原创 2016-07-15 15:16:12 · 699 阅读 · 0 评论 -
Play on Words(欧拉回路+并查集)
Play on Words Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 11628 Accepted: 3980 DescriptionSome of the secret doors contain a very interesting word puzzle. The team of arch原创 2016-07-18 20:37:37 · 710 阅读 · 0 评论 -
Door Man(欧拉回路)
Door Man Description You are a butler in a large mansion. This mansion has so many rooms that they are merely referred to by number (room 0, 1, 2, 3, etc…). Your master is a particularly absent-minde原创 2016-07-18 20:44:30 · 901 阅读 · 0 评论 -
一笔画问题(欧拉通路)
一笔画问题 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描述 zyc从小就比较喜欢玩一些小游戏,其中就包括画一笔画,他想请你帮他写一个程序,判断一个图是否能够用一笔画下来。规定,所有的边都只能画一次,不能重复画。输入 第一行只有一个正整数N(N<=10)表示测试数据的组数。 每组测试数据的第一行有两个正整数P,Q(P< =1000,Q< =2000),分别表示原创 2016-07-19 20:19:06 · 1740 阅读 · 0 评论 -
城市平乱(dijkstra)
时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 南将军统领着N个部队,这N个部队分别驻扎在N个不同的城市。他在用这N个部队维护着M个城市的治安,这M个城市分别编号从1到M。现在,小工军师告诉南将军,第K号城市发生了暴乱,南将军从各个部队都派遣了一个分队沿最近路去往暴乱城市平乱。现在已知在任意两个城市之间的路行军所需的时间,你作为南将军麾下最厉害的程序员,请你编写一原创 2016-07-19 20:26:25 · 642 阅读 · 0 评论 -
学霸的迷宫(广搜)
问题描述: 学霸抢走了大家的作业,班长为了帮同学们找回作业,决定去找学霸决斗。但学霸为了不要别人打扰,住在一个城堡里,城堡外面是一个二维的格子迷宫,要进城堡必须得先通过迷宫。因为班长还有妹子要陪,磨刀不误砍柴功,他为了节约时间,从线人那里搞到了迷宫的地图,准备提前计算最短的路线。可是他现在正向妹子解释这件事情,于是就委托你帮他找一条最短的路线。 输入格式 第一行两个整数n, m,为迷宫的长原创 2016-04-09 10:57:44 · 852 阅读 · 0 评论 -
The Unique MST
The Unique MST Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 26786 Accepted: 9599 DescriptionGiven a connected undirected graph, tell if its minimum spanning tree is unique.原创 2016-07-14 21:10:18 · 665 阅读 · 0 评论 -
(POJ 1062)昂贵的聘礼 在可选的顶点中求最短路 dijkstra + 枚举
昂贵的聘礼 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 46354 Accepted: 13753 Description年轻的探险家来到了一个印第安部落里。在那里他和酋长的女儿相爱了,于是便向酋长去求亲。酋长要他用10000个金币作为聘礼才答应把女儿嫁给他。探险家拿不出这么多金币,便请求酋长降低转载 2016-10-28 18:28:52 · 557 阅读 · 0 评论 -
(POJ 2253)Frogger 求所有可达路径中的最大边的最小值 dijkstra || floyd 变形
Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 38822 Accepted: 12492 DescriptionFreddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fiona F原创 2016-10-29 18:21:03 · 1218 阅读 · 0 评论 -
(LeetCode 743)网络延迟时间 [最短路 + bellman-ford]
743. 网络延迟时间有 N 个网络节点,标记为 1 到 N。给定一个列表 times,表示信号经过有向边的传递时间。 times[i] = (u, v, w),其中 u 是源节点,v 是目标节点, w 是一个信号从源节点传递到目标节点的时间。现在,我们向当前的节点 K 发送了一个信号。需要多久才能使所有节点都收到信号?如果不能使所有节点收到信号,返回 -1。注意:N 的范围在 [1, ...原创 2019-02-27 19:12:07 · 420 阅读 · 0 评论 -
(CCF 201403-4)无线网络 最短路变形:节点访问限制 + [SPFA]
问题描述 目前在一个很大的平面房间里有 n 个无线路由器,每个无线路由器都固定在某个点上。任何两个无线路由器只要距离不超过 r 就能互相建立网络连接。 除此以外,另有 m 个可以摆放无线路由器的位置。你可以在这些位置中选择至多 k 个增设新的路由器。 你的目标是使得第 1 个路由器和第 2 个路由器之间的网络连接经过尽量少的中转路由器。请问在最优方案下中转路由器的最少个数是多少?原创 2017-10-21 21:23:29 · 619 阅读 · 0 评论 -
(POJ 1511)Invitation Cards 有向图来回最短路 + SPFA (复习必看题)
Invitation Cards Time Limit: 8000MS Memory Limit: 262144K Total Submissions: 29342 Accepted: 9808 DescriptionIn the age of television, not many people attend theater performances. Antiqu原创 2017-10-06 10:42:51 · 608 阅读 · 0 评论 -
(POJ 3687)Labeling Balls [逆top序列] 求按照某种排列方式的字典序最小的top序列
Labeling Balls Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 14922 Accepted: 4372 DescriptionWindy has N balls of distinct weights from 1 unit to N units. Now he tries to la原创 2017-10-11 16:40:09 · 573 阅读 · 0 评论 -
(POJ 3660)Cow Contest [详解] [floyd] 传递闭包 确定top序列顺序
Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13189 Accepted: 7337 DescriptionN (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programmin原创 2017-10-11 15:23:59 · 487 阅读 · 0 评论 -
(POJ 2367)Genealogical tree [top序列] 入门
Genealogical tree Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6116 Accepted: 4034 Special Judge DescriptionThe system of Martians’ blood relations is confusing enough. A原创 2017-10-11 10:34:48 · 334 阅读 · 0 评论 -
[欧拉图总结]
http://www.cnblogs.com/pandy/archive/2009/05/07/1452209.htmlhttp://bchine.com/mjmjmtl/?p=241参考以上:判断欧拉路,欧拉回路:注意图联通,可以DFS或者并查集一.无向图欧拉回路:每个顶点度数都是偶数欧拉路:所有点度数为偶数,或者只有2个点度数为奇数二.有向图(非混合)欧拉回路:每个顶点入度等于出度欧拉路:每个顶转载 2017-10-09 21:10:36 · 880 阅读 · 0 评论 -
(POj 2230)Watchcow [有向欧拉图] 输出欧拉回路
Watchcow Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 8436 Accepted: 3670 Special Judge DescriptionBessie’s been appointed the new watch-cow for the farm. Every night, it原创 2017-10-08 15:51:58 · 617 阅读 · 0 评论 -
(POJ 1041)John's trip [无向欧拉图] 输出字典序最小的欧拉回路
John’s trip Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9278 Accepted: 3112 Special Judge DescriptionLittle Johnny has got a new car. He decided to drive around the town原创 2017-10-09 11:30:09 · 834 阅读 · 0 评论 -
(POJ 1847)Tram 简单最短路 spfa
Tram Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 16731 Accepted: 6210 DescriptionTram network in Zagreb consists of a number of intersections and rails connecting some of原创 2017-10-07 13:38:40 · 347 阅读 · 0 评论 -
(POJ 1797)Heavy Transportation 最大生成树|最短路变形 (理解最短路核心思想好题)
Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 40123 Accepted: 10544 DescriptionBackground Hugo Heavy is happy. After the breakdown of the Cargolifter原创 2017-10-07 12:57:09 · 514 阅读 · 0 评论 -
(POJ 3352)无向图的边双连通分量模板题 + 在一个图中最少加几条边可以使得图边双连通
Road Construction Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 11779 Accepted: 5899 DescriptionIt’s almost summer time, and that means that it’s almost summer construction原创 2017-04-20 20:07:01 · 1486 阅读 · 0 评论 -
(POJ 2186)Popular Cows 强连通分量 + 缩点图
Popular CowsTime Limit: 2000MS Memory Limit: 65536K Total Submissions: 33190 Accepted: 13517 DescriptionEvery cow’s dream is to become the most popular cow in the herd. In a herd of N (1原创 2017-04-19 20:18:56 · 517 阅读 · 0 评论 -
无向图的割顶和桥,无向图的双连通分量入门详解及模板
割顶和桥:对于无向图G,如果删除某个节点u后,连通分量数目增加,则称u为图的割顶;如果删除某条边后,连通分量数目增加,则称该边为图的桥。对于连通图删除割顶或桥后都会使得图不再连通以下我,我们利用dfs的性质来快速找出一个连通图中的所有的割顶和桥 首先我们要引入”时间戳”这个概念:时间戳:表示在进行dfs时,每个节点被访问的先后顺序。每个节点会被标记两次,分别用pre[],和post[]表示。 例原创 2017-04-14 22:56:11 · 5905 阅读 · 3 评论 -
有向图的强连通分量Kosaraju算法 和 Tarjan算法思维详解及代码模板
有向图的强连通分量 SCC: 在有向图G中,如果两个顶点间相互可达,则称两个顶点强连通(strongly connected)。如果有向图G的每两个顶点都强连通,称G是一个强连通图。非强连通有向图的极大强连通子图,称为强连通分量(strongly connected components)。如果把每个scc看成一个节点,那么有向图中所有的scc就构成了一个scc图Kosaraju算法的思想: 在讲原创 2017-04-18 19:40:05 · 3440 阅读 · 1 评论 -
(HDU 5723)Abandoned country <最小生成树 + 树上所有两点之间的距离的期望> 多校训练1
Abandoned country Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 4941 Accepted Submission(s): 1249Problem Description An abandoned countr原创 2017-01-06 20:43:24 · 954 阅读 · 0 评论 -
(NYoj 239)月老的难题--裸最大匹配
题目:月老的难题 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 月老准备给n个女孩与n个男孩牵红线,成就一对对美好的姻缘。现在,由于一些原因,部分男孩与女孩可能结成幸福的一家,部分可能不会结成幸福的家庭。现在已知哪些男孩与哪些女孩如果结婚的话,可以结成幸福的家庭,月老准备促成尽可能多的幸福家庭,请你帮他找出最多可能促成的幸福家庭数量吧。假设男孩们分别编号为1~原创 2016-07-29 20:29:17 · 429 阅读 · 0 评论 -
(NYoj 237)游戏高手的烦恼 --二部图最大匹配,匈牙利算法
题目: 游戏高手的烦恼 时间限制:1000 ms | 内存限制:65535 KB 难度:5 描述 有一位传说级游戏高手,在闲暇时间里玩起了一个小游戏,游戏中,一个n*n的方块形区域里有许多敌人,玩家可以使用炸弹炸掉某一行或者某一列的所有敌人。他是种玩什么游戏都想玩得很优秀的人,所以,他决定,使用尽可能少的炸弹炸掉所有的敌人。 现在给你一个游戏的状态,请你帮助他判断最少需要多少个炸弹才原创 2016-07-29 20:22:39 · 459 阅读 · 0 评论 -
Top序列
问题描述: 对输入的有向图进行拓扑排序,并输出一个拓扑有序序列;若果存在有向环则输出:Network has a cycle! 样例输入: 6 8 1 2 1 4 2 6 3 2 3 6 5 1 5 2 5 6 6 8 1 3 1 2 2 5 3 4 4 2 4 6 5 4 5 6 0 0 样例输出: 5 1 4 3 2 6 Network has a原创 2016-07-13 10:44:38 · 665 阅读 · 0 评论 -
Bus Pass-ZOJ2913
Bus PassTime Limit: 5 Seconds Memory Limit: 32768 KBYou travel a lot by bus and the costs of all the seperate tickets are starting to add up.Therefore you want to see if it might be advantageous f原创 2016-07-12 08:36:00 · 548 阅读 · 0 评论 -
Tempter of the Bone
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 104767 Accepted Submission(s): 28451Problem Description The doggie fou原创 2016-07-11 16:40:46 · 291 阅读 · 0 评论