![](https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
图论
Marcus-Bao
这个作者很懒,什么都没留下…
展开
-
poj2237 Bad Cowtractors 最大生成树
D - Bad CowtractorsTime Limit:1000MS Memory Limit:65536KB 64bit IO Format:%lld & %lluSubmit StatusDescriptionBessie has been hired to build a cheap internet network among原创 2016-11-10 21:07:40 · 584 阅读 · 0 评论 -
codeforces 505B Mr. Kitayuta's Colorful Graph
Description一个无向图包含n个点m条边,顶点编号从1到n。 对于每条边有颜色ci, 连接着顶点 ai 和 b i.下面有q个询问.每条询问有两个整数 — ui 和 vi.找到满足下面条件的颜色个数: 同一种颜色的路径连接顶点 ui 和 顶点 vi Input第一行是两个整数 — n and m (2 ≤ n ≤ 100, 1 ≤原创 2016-11-23 20:20:20 · 450 阅读 · 0 评论 -
PAT A 1122. Hamiltonian Cycle (25) 哈密顿回路+dfs
The "Hamilton cycle problem" is to find a simple cycle that contains every vertex in a graph. Such a cycle is called a "Hamiltonian cycle".In this problem, you are supposed to tell if a given cycl原创 2017-02-28 16:02:39 · 935 阅读 · 0 评论 -
算法训练 安慰奶牛 最小生成树
问题描述Farmer John变得非常懒,他不想再继续维护供奶牛之间供通行的道路。道路被用来连接N个牧场,牧场被连续地编号为1到N。每一个牧场都是一个奶牛的家。FJ计划除去P条道路中尽可能多的道路,但是还要保持牧场之间 的连通性。你首先要决定那些道路是需要保留的N-1条道路。第j条双向道路连接了牧场Sj和Ej(1 j j <= N; Sj != Ej),而且走完它需要Lj的时间原创 2017-02-20 10:35:25 · 719 阅读 · 0 评论 -
算法训练 最短路 Bellman-Ford
问题描述给定一个n个顶点,m条边的有向图(其中某些边权可能为负,但保证没有负环)。请你计算从1号点到其他点的最短路(顶点从1到n编号)。输入格式第一行两个整数n, m。接下来的m行,每行有三个整数u, v, l,表示u到v有一条长度为l的边。输出格式共n-1行,第i行表示1号点到i+1号点的最短路。样例输入3 31原创 2017-02-21 16:07:13 · 490 阅读 · 0 评论 -
pat L2-001. 紧急救援 dijkstra变形+记录路径
作为一个城市的应急救援队伍的负责人,你有一张特殊的全国地图。在地图上显示有多个分散的城市和一些连接城市的快速道路。每个城市的救援队数量和每一条连接两个城市的快速道路长度都标在地图上。当其他城市有紧急求助电话给你的时候,你的任务是带领你的救援队尽快赶往事发地,同时,一路上召集尽可能多的救援队。输入格式:输入第一行给出4个正整数N、M、S、D,其中N(2输出格式:第一行原创 2017-02-23 21:53:39 · 1115 阅读 · 0 评论 -
CodeForces - 450D Jzzhu and Cities spfa变形
D. Jzzhu and Citiestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputJzzhu is the president of country A. Th原创 2017-03-06 11:12:54 · 461 阅读 · 0 评论 -
hihocoder #1273 清理海报 建图思想+dfs+状态压缩记录 好题!
描述小Hi实验室所在的建筑一楼有一个用于贴海报的黑板,不停的有新的海报往上贴,也会安排人员不断的对海报进行清理,而最近,轮到了小Hi去对海报进行清理。黑板是一块W*H大小的区域,如果以左下角为直角坐标系的话,在上次清理后第i张贴上去的海报可以视作左下角为(X1i, Y1i),右上角为(X2i, Y2i)的一个矩形。撕去一张海报会导致所有覆盖在其上的海报都被同时撕掉(这样被称为连带,原创 2017-03-06 12:26:40 · 684 阅读 · 0 评论 -
POJ 2449 Remmarguts' Date A*+spfa求第k最短路
题目链接题意:给你个图 让你求s到t的第k短路\思路:首先讲讲A*算法吧。众所周知,A*算法就是启发式搜索,基本形式就是这样:f(x)=g(x)+h(x);其中f(x)代表在x点所需要的总代价,而g(x)代表:从源点到x点已经耗费的实际代价,h(x)代表从x到终点需要的估计代价,这个函数是一个估计值.而从x到终点真正需要的代价为h*(x),在整个启发式搜索中我们必须原创 2017-04-04 13:49:54 · 405 阅读 · 0 评论 -
第七届福建省赛 7/10
题目链接以下博文参考大牛的题解OTZ 真的是越发认识到自己菜到爆炸,思维思维跟不上,算法算法也不会.我还会干什么....Problem 2262 Best Friend ForeverProblem 2263 BondProblem 2264 Card Game (First Edition)这原创 2017-07-19 20:21:57 · 552 阅读 · 0 评论 -
2017 Multi-University Training Contest - Team 9 待补 hdu 6161 ~6170
hdu6151 FFF at Valentine题意:种种原因...签到题这次都没出,先是各种猜题意,然后题意对了,图论小白并不会做,队友卡在02主席树....给你一个无环,无重边的有向图,问你任意两点,是否存在路径使得其中一点能到达另一点思路: 一开始想的是强联通分量缩点,缩点后剩下的点必须构成一条链,于是通过判断每个点的出入度不能大于等于原创 2017-08-23 15:36:01 · 378 阅读 · 0 评论 -
1111. Online Map (30) 最短路 + 记录路径(回溯)
传送门题意:给了图,以及s和t,让你求s到t花费的最短路程、最短时间,以及输出对应的路径。 对于最短路程,如果路程一样,输出时间最少的。 对于最短时间,如果时间一样,输出节点数最少的。 如果最短路程和最短时间路径一样,合并输出一次即可。思路:直接一次spfa即可,在过程中同时记录最短路和最短时间,同时记录最短路所需要的时间,以及最短时间所经过的节点数.一开始理解错题意了,当最短...原创 2018-03-16 16:30:11 · 322 阅读 · 0 评论 -
codevs 1041 Car的旅行路线
传送门思路:这个题目预处理起来比较麻烦,由于题目中说了一个城市有四个机场,但是指给定三个,所以需要我们自己去求第四个点,这个过程就需要枚举哪一个点为直角顶点然后再求第四个。求出第四个点后在预处理出任意两个机场之间的花费(注意区分同一个城市和不同城市),然后再跑dij即可. 求第四个点只需枚举一下哪个点所对应的边为斜边在通过斜率计算即可#include<bits/stdc++.h>#...原创 2018-03-10 16:34:01 · 262 阅读 · 0 评论 -
PAT 1018. Public Bike Management (30) (最短路+DFS)
传送门题意: 从0号点到给定的有问题的点en,要保证每个点自行车数量为Cmax的一半,一个点的自行车数量可以被这条路径上前几个点多的自行车来补. 问你从0到问题点en的最短路径,如果最短路径相同,输出需要从0点携带的自行车数量最小的路径,如果还相同输出该路径上需要带回去最少的路径。(需要将路径上经过的所有点的自行车数量都变为完美的)思路: 如果单纯的路径最短,或者带出来的自行车数量最小...原创 2018-03-16 22:17:28 · 255 阅读 · 0 评论 -
POJ 3268 - Silver Cow Party dijkstra+转置矩阵
One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to attend the big cow party to be held at farm #X (1 ≤ X ≤ N). A total of M (1 ≤ M ≤ 100,000) unidirectional (one-way原创 2016-12-06 00:01:43 · 606 阅读 · 0 评论 -
POJ 1797 Heavy Transportation dijkstra 变形
C - Heavy TransportationTime Limit:3000MS Memory Limit:30000KB 64bit IO Format:%lld & %lluSubmit StatusDescriptionBackground Hugo Heavy is happy. After the breakdown of原创 2016-12-04 00:24:14 · 1899 阅读 · 0 评论 -
POJ 2253 Frogger dijkstra 变形
B - FroggerTime Limit:1000MS Memory Limit:65536KB 64bit IO Format:%lld & %lluSubmit StatusDescriptionFreddy Frog is sitting on a stone in the middle of a lake. Suddenly h原创 2016-12-04 00:01:49 · 526 阅读 · 0 评论 -
poj 2395 Out of Hay 求最小生成树
E - Out of HayTime Limit:1000MS Memory Limit:65536KB 64bit IO Format:%lld & %lluSubmit StatusDescriptionThe cows have run out of hay, a horrible event that must be remedi原创 2016-11-10 21:10:39 · 459 阅读 · 0 评论 -
POJ 3723 conscription 最大生成树
F - ConscriptionTime Limit:1000MS Memory Limit:65536KB 64bit IO Format:%lld & %lluSubmit StatusDescriptionWindy has a country, and he wants to build an army to protect原创 2016-11-10 21:15:09 · 544 阅读 · 0 评论 -
poj 2236 Wireless Network 并查集
G - Wireless NetworkTime Limit:10000MS Memory Limit:65536KB 64bit IO Format:%lld & %lluSubmit StatusDescriptionAn earthquake takes place in Southeast Asia. The ACM (Asia原创 2016-11-10 21:26:28 · 776 阅读 · 0 评论 -
POJ 3026 Borg Maze (bfs+prim)
Borg MazeTime Limit:1000MS Memory Limit:65536KB 64bit IO Format:%lld & %lluSubmit StatusDescriptionThe Borg is an immensely powerful race of enhanced humanoids from the d原创 2016-11-15 19:03:35 · 488 阅读 · 0 评论 -
POJ 1258 Agri-Net 最小生成树 prim
C - Agri-NetTime Limit:1000MS Memory Limit:10000KB 64bit IO Format:%lld & %lluSubmit StatusDescriptionFarmer John has been elected mayor of his town! One of his campaign原创 2016-11-12 19:16:09 · 478 阅读 · 0 评论 -
POJ 1703 Find them, Catch them 关系并查集
H - Find them, Catch themTime Limit:1000MS Memory Limit:10000KB 64bit IO Format:%lld & %lluSubmit StatusDescriptionThe police office in Tadu City decides to say ends to t原创 2016-11-16 20:28:19 · 454 阅读 · 0 评论 -
POJ 1679 Kruskal求次小生成树
The Unique MSTTime Limit:1000MS Memory Limit:10000KB 64bit IO Format:%lld & %lluSubmit StatusDescriptionGiven a connected undirected graph, tell if its minimum spanning t原创 2016-11-13 21:09:39 · 523 阅读 · 0 评论 -
POJ 1611 The Suspects 并查集
N - The SuspectsTime Limit:1000MS Memory Limit:20000KB 64bit IO Format:%lld & %lluSubmit StatusDescriptionSevere acute respiratory syndrome (SARS), an atypical pneumonia原创 2016-11-13 21:18:38 · 620 阅读 · 0 评论 -
Codeforces Round #376 (Div. 2) C. Socks (map)
A - SocksTime Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64uSubmit StatusDescriptionArseniy is already grown-up and independent. His mother decided to l原创 2016-11-12 19:52:44 · 872 阅读 · 0 评论 -
POJ 1789 Truck History
M - Truck HistoryTime Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %lluSubmit StatusDescriptionAdvanced Cargo Movement, Ltd. uses trucks of different types. Som原创 2016-11-18 20:45:10 · 303 阅读 · 0 评论 -
codeforces #363 fix a tree 并查集
Fix a TreeTime Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64uSubmit StatusDescriptionA tree is an undirected connected graph without cycles.Let's cons原创 2016-11-15 19:33:06 · 482 阅读 · 0 评论 -
POJ 3522 slim span Kruskal
Slim SpanTime Limit:5000MS Memory Limit:65536KB 64bit IO Format:%lld & %lluSubmit StatusDescriptionGiven an undirected weighted graph G, you should find one of spanning原创 2016-11-15 20:17:23 · 407 阅读 · 0 评论 -
POJ 2387 Til the Cows Come Home dijkstraA
A - Til the Cows Come HomeTime Limit:1000MS Memory Limit:65536KB 64bit IO Format:%lld & %lluSubmit StatusDescriptionBessie is out in the field and wants to get back to the原创 2016-12-03 23:31:37 · 471 阅读 · 0 评论 -
计蒜客 封印之门(思维+Floyd)
传送门思路: 个人感觉是很巧妙的一题啊,总觉得很熟悉但就是差点意思... 首先分析一下bfs是没戏了,每个字母最多26中变换方法(可以自己变成自己),最长1000,26^1000 ,hhh 感觉这题加深了对Floyd的理解吧,由于是小写字母也就是最多有26个城市,我们可以先不去考虑整个字符串,只看把某个字符变为要求的字符需要几步,然后在遍历整个串求出总共需要的步数即可.我们把每一...原创 2018-03-30 21:41:53 · 363 阅读 · 0 评论