图论
eazo
这个作者很懒,什么都没留下…
展开
-
Expectation(生成树计数)
题目描述You are given an undirected graph consisting of n vertices with m weighted edges. We define the weight of a spanning tree as the bitwise AND of all edges’ weight in spanning tree.Now select a spanning tree randomly, you should calculate the expected原创 2020-08-06 22:32:17 · 231 阅读 · 0 评论 -
小Y的图(kruskal重构树)
题目描述小Y有一个n个点的无向图,图中的每个点从1到n标号。图中还有m条边,每条边有一个长度。小Y有Q个询问,每次询问两个点所有路径中,最长的边最小值是多少,若这两个点之间没有任何路径,输出 -1。输入第一行三个整数n、m和Q。接下来m行每行三个整数x、y、z(1≤x,y≤n,1≤z≤1000000),表示有一条连接x和y长度为z的边。接下来Q行每行两个整数x、y(x≤y),表示一组询问。输出Q行每行一个整数,表示一组询问的答案。样例输入5 5 41 2 31 3 23 2 11原创 2020-07-24 17:17:39 · 316 阅读 · 0 评论 -
路径和(cdq分治)
题目描述对于一张有向图,定义d(u,v,w)为从u号点出发,不经过v号点,最终到达w号点的最短路径长度。如果不存在这样的路径,d(u,v,w)的值为−1。你也可以认为d(u,v,w)是删去v点和其相关的边后,图中u到w的最短路。现在给定这张有向图每两个点之间的有向边的长度(如果不存在连边则为−1),对于所有满足1≤x,y,z≤n,x≠y,y≠z的有序数对(x,y,z),求它们d(x,y,z)的和。你可以借助样例一解释来理解上面这句话的意思。输入第一行输入一个正整数n,表示该地区的点数。接下来输原创 2020-05-31 21:34:20 · 540 阅读 · 0 评论 -
Weights Distributing(bfs 前缀和)
You are given an undirected unweighted graph consisting of n vertices and m edges (which represents the map of Bertown) and the array of prices p of length m. It is guaranteed that there is a path bet...原创 2020-04-22 22:21:53 · 292 阅读 · 0 评论 -
走格子(bfs+dji)
题目描述CYJ想找到他的小伙伴FPJ,.CYJ和FPJ现在位于一个房间里,这个房间的布置可以看成一个N行M列的矩阵,矩阵内的每一个元素会是下列情况中的一种:1.障碍区域—这里有一堵墙(用‘#’表示).2.这是CYJ最开始在的区域(用‘C’表示).3.这是FPJ在的区域(用‘F’表示).4.空区域(用‘.’表示).CYJ携带了一个所谓传送枪的东西,这是一把可以创造传送门的枪械,在每一次行...原创 2020-04-19 21:56:47 · 461 阅读 · 0 评论 -
队爷的讲学计划(tarjan +拓扑排序)
题目描述队爷为了造福社会,准备到各地去讲学。他的计划中有n个城市,从u到v可能有一条单向道路,通过这条道路所需费用为q。当队爷在u城市讲学完之后,u城市会派出一名使者与他同行,只要使者和他在一起,他到达某个城市就只需要花1的入城费且只需交一次,在路上的费用就可免去。。但是使者要回到u城市,所以使者只会陪他去能找到回u城市的路的城市。。队爷从1号城市开始讲学,若他在u号城市讲学完毕,使者会带他尽可...原创 2020-04-12 22:49:53 · 255 阅读 · 0 评论 -
Coins Respawn(SPFA 最长路)
题目描述There is a directed graph with N vertices numbered 1 to N and M edges. The i-th edge is directed from Vertex Ai to Vertex Bi, and there are Ci coins placed along that edge. Additionally, there is...原创 2020-02-09 17:54:43 · 407 阅读 · 0 评论 -
Bucket Brigade(bfs)
题目描述A fire has broken out on the farm, and the cows are rushing to try and put it out!The farm is described by a 10×10 grid of characters like this:…………B………R…………L……The character ‘B’ repre...原创 2020-02-07 23:46:11 · 747 阅读 · 0 评论 -
Virus Tree 2(树)
题目描述You are given a tree with N vertices and N−1 edges. The vertices are numbered 1 to N, and thei-th edge connects Vertex ai and bi.You have coloring materials of K colors. For each vertex in the ...原创 2020-02-06 17:57:11 · 491 阅读 · 0 评论 -
重要人物(最短路)
题目描述某重要人物P要寻访城市C的G个地方,由于该人物非常重要,交警打算对人物P行走的街道进行临时封道(不准普通市民进入,但如果在封道前进入的可以继续行走,也可以正常出去)。当人物P进入这条街道之前和P走出这条街道之后,普通市民都可以正常进入该街道。比如,P在第10分钟期间进入街道X,并要X街道上行走5分钟,则在第10、11、12、13、14分钟期间,普通市民不可以进入X街道,市民可以在第9分...原创 2020-02-06 17:49:43 · 261 阅读 · 0 评论 -
Hopscotch Addict(分层图最短路)
题目描述Ken loves ken-ken-pa (Japanese version of hopscotch). Today, he will play it on a directed graph G. G consists of N vertices numbered 1 to N, and M edges. The i-th edge points from Vertex ui to V...原创 2020-02-05 19:54:42 · 368 阅读 · 0 评论 -
Time is Mooney(dp)
题目描述Bessie is conducting a business trip in Bovinia, where there are N (2≤N≤1000) cities labeled 1…N connected by M (1≤M≤2000) one-way roads. Every time Bessie visits city i, Bessie earns mi moonies ...原创 2020-02-03 17:08:57 · 361 阅读 · 0 评论 -
路径统计(dfs)
题目描述小W所在城市有n个学校(编号从1到n),学校与学校之间用一些双向道路连接。我们已知任意两个学校一定是可以相互导到达的(直接或间接)。现在有两个学校a和b(1≤a,b≤n,a≠b)。假如当前有两个学校x和y(x≠a,x≠b,y≠a,y≠b),如果我们要从x走到y一定会经过a和b(经过a,b的顺序没有关系),那么我们就把这个x和y称为一个神奇的点对,注意x和y交换顺序也只能作为同一个点对。...原创 2020-02-01 20:21:20 · 1484 阅读 · 0 评论 -
博览会(树形DP)
题目描述某市正在举行一场大型博览会,博览会有 n 个展馆,每个展馆里有若干个展台。这 n 个展馆以 及它们之间的道路可以看成一棵二叉树,博览会的出入口设在根节点——1 号展馆,小明将从这里 出发乘坐电瓶车到各个展馆参观,并最终回到 1 号展馆出口。由于路程差异,乘坐电瓶车往返不同展馆间的费用也有所区别。出发时,小明的乘车卡里余额 为 k。他现在想知道,若全程都乘坐电瓶车,他最多能参观多少个展台...原创 2020-01-31 17:44:42 · 327 阅读 · 0 评论 -
魔环上的树(组合数学 图论)
题目描述大魔头路西法拥有一样可怕的神器——魔环,魔环上有着n个用来摆放神珠的位置,并且这n个位置两两不重叠。当路西法想要施放某种法术时,他便会将n个神珠放在这n个位置上,神珠就位后,有着“亲密联系”的神珠之间将产生一道丝线,如果有两条丝线相交且交点不在顶点处,路西法的法术将会失效,现在路西法告诉你他的那些神珠之间有着“亲密联系”,要求你告诉他有多少种摆放神珠的方案使法术顺利施放?顺便提一句: ...原创 2020-01-31 00:47:44 · 262 阅读 · 0 评论 -
飞行计划(最短路)
题目描述已知地图上一共有n个机场,Alice要从1号机场飞到n号机场。从i号机场飞行到j号机场需要消耗dist(i,j)个单位的油量,其中 dist(i,j)为i号机场和j号机场之间的欧几里得距离。Alice可以选择在任意机场起降和加油。飞机油箱最多可以保存u单位的燃油。考虑到可能遇到的极端天气,某些机场在某些时候不具备降落的条件。所以出于安全的考虑,当他飞到一个机场的时候,必须保证飞机剩...原创 2020-01-28 20:57:03 · 542 阅读 · 0 评论 -
战略威慑(树的直径)
题目描述马奥雷利亚诺布恩迪亚上校发动了他的第三十二次战争,让我们祝他好运。马孔多附近有n个城市,有n-1条双向道路连通这些城市。上校想通过摧毁两条公路的方式对当局予以威慑。但是上校的老师告诉他为了战略目的这两条路不可以有共同的城市。这次行动对当局的威慑效果将等于两条路径的长度的乘积。假设每条道路的长度等于1,并且路径的长度等于道路的数量。请你帮上校造成最大的威慑。输入单组测试数据。第一行是一...原创 2019-11-18 17:28:58 · 191 阅读 · 0 评论 -
赛艇表演(图论)
题目描述小明去某个地区观看赛艇比赛,这个地区共有n个城市和m条道路,每个城市都有赛艇比赛,在第i个城市观看赛艇表演的价钱为ai, 去其他城市观看也需要支付赛艇表演的价格。任意两个城市之间通过一条公路连接,并且道路是双向通行的, 观看赛艇比赛时经过的每一条道路都要支付一定的过路费,观看完比赛返回家时经过的每一条道路也要支付过路费。对于每个城市u,你需要为小明确定一个城市v,使得从u出发,前往v看...原创 2019-11-13 14:42:55 · 155 阅读 · 0 评论 -
Watch Where You Step(拓扑排序)
题目描述You are an employee at the local zoo and have recently been promoted from excretory extraction to over-seeing the layout of all the sidewalks throughout the property. Currently all the sidewalks ...原创 2019-10-26 21:46:17 · 244 阅读 · 0 评论 -
跑路(倍增+floyd)
题目描述n+e的工作不仅繁琐,公司更有苛刻的规定,hzwer要求n+e每天早上在6:00之前到达公司发题目给小朋友做,否则这个月工资清零。可是n+e偏偏又有赖床的坏毛病。于是为了保住自己的工资,n+e买了一个十分牛B的空间跑路器,每秒钟可以跑2kkm(k∈N)。当然,这个机器是用int存的,所以总跑路长度不能超过2147483647km。n+e的家到hzwer公司的路可以看做一个有向图,n+...原创 2019-10-17 22:28:06 · 125 阅读 · 0 评论 -
Telephone Lines(最短路+二分)
题目描述Farmer John wants to set up a telephone line at his farm. Unfortunately, the phone company is uncooperative, so he needs to pay for some of the cables required to connect his farm to the phone sy...原创 2019-09-09 22:15:47 · 832 阅读 · 0 评论 -
Balanced Neighbors(图)
题目描述You are given an integer N. Build an undirected graph with N vertices with indices 1 to N that satisfies the following two conditions:·The graph is simple and connected.·There exists an integer...原创 2019-07-08 23:43:27 · 150 阅读 · 0 评论 -
花园(最大生成树)
题目描述小N经常去小T家的花园里散步,小T家的花园有N个长的⼀样的亭⼦和M条道路连接着亭⼦,但是小T的花园太过于乱了,小N作为⼀个路痴经常进去了之后找不到出来的路,⼀直在环里面绕圈。于是小N要让小T把其中的某些路种上向日葵,使得剩下的路不会出现环。因为向日葵不⽅便种,⽽第i条路长Li,需要Li个向日葵去种,于是小T想知道他最少要种多少向日葵才能满⾜小N的要求呢?输入第⼀⾏两个整数N、M,表...原创 2019-10-09 22:46:16 · 320 阅读 · 0 评论 -
transaction transaction transaction(树形DP 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...原创 2019-10-05 01:11:26 · 205 阅读 · 0 评论 -
free (多层图最短路)
题目描述Your are given an undirect connected graph.Every edge has a cost to pass.You should choose a path from S to T and you need to pay for all the edges in your path. However, you can choose at most k...原创 2019-08-23 20:30:35 · 248 阅读 · 0 评论 -
Ratatöskr
题目描述Ratatöskr is a squirrel that lives in a giant (but finite) mythical tree called Yggdrasil. He likes to gossip, which sets the other inhabitants of the tree against each other. Ratatöskr is thus h...原创 2019-08-20 10:11:42 · 347 阅读 · 0 评论 -
Plug It In!(二分图匹配)
题目描述Adam just moved into his new apartment and simply placed everything into it at random. This means in particular that he did not put any effort into placing his electronics in a way that each one ...原创 2019-08-19 10:35:41 · 182 阅读 · 0 评论 -
Joyride(分层图最短路)
题目描述It is another wonderful sunny day in July – and you decided to spend your day together with your little daughter Joy. Since she really likes the fairy-park in the next town, you decided to go the...原创 2019-08-19 10:25:11 · 330 阅读 · 0 评论 -
路
题目描述Farmer John 热衷于散步,每天早上他都要从 1 号仓库走到 n 号仓库。 Farmer John 家的 n 个仓库被 m 条双向道路连通起来,每条道路有一个长度 w。而Farmer John 又不喜欢走路,所以他走的是从 1 号仓库到 n 号仓库的最短路。但是 Farmer 的奶牛们总想搞点事情,他们计划着把 m 条道路的其中一条变成原来长度的 2 倍,使得 Farmer J...原创 2019-08-01 09:04:27 · 89 阅读 · 0 评论 -
可达性统计(图 拓扑排序 bitset)
题目描述给定一张N个点M条边的有向无环图,分别统计从每个点出发能够到达的点的数量。N,M≤30000。输入第一行两个整数N,M,接下来M行每行两个整数x,y,表示从x到y的一条有向边。输出共N行,表示每个点能够到达的点的数量。样例输入10 103 82 32 55 95 92 33 94 82 104 9样例输出1633211111思路找...原创 2019-05-28 19:28:37 · 344 阅读 · 0 评论 -
Communication(Tarjan)
题目描述The Ministry of Communication has an extremely wonderful message system, designed by the President himself. For maximum efficiency, each office in the Ministry can send a message directly to some...原创 2019-05-01 00:12:42 · 119 阅读 · 0 评论 -
**Made In Heaven(a*)
题目描述One day in the jail, F·F invites Jolyne Kujo (JOJO in brief) to play tennis with her. However, Pucci the father somehow knows it and wants to stop her. There are N spots in the jail and M roads ...原创 2019-05-01 20:22:38 · 164 阅读 · 0 评论 -
Bumped!(dijstra)
题目描述Peter returned from the recently held ACM ICPC World finals only to find that his return flight was overbooked and he was bumped from the flight! Well, at least he wasn’t beat up by theairline a...原创 2019-04-15 19:57:22 · 265 阅读 · 0 评论 -
每日一练 19.2.21
noip提高组2014无线网络发射器选址题目描述随着智能手机的日益普及,人们对无线网的需求日益增大。某城市决定对城市内的公共场所覆盖无线网。假设该城市的布局为由严格平行的129 条东西向街道和129 条南北向街道所形成的网格状,并且相邻的平行街道之间的距离都是恒定值 1 。东西向街道从北到南依次编号为0,1,2…128 , 南北向街道从西到东依次编号为0,1,2…128 。东西向街道和南...原创 2019-02-21 16:41:27 · 230 阅读 · 0 评论 -
最优贸易
题目描述C 国有 n 个大城市和 m 条道路,每条道路连接这 n 个城市中的某两个城市。任意两个城市之间最多只有一条道路直接相连。这 m 条道路中有一部分为单向通行的道路,一部分为双向通行的道路,双向通行的道路在统计条数时也计为 1 条。C 国幅员辽阔,各地的资源分布情况各不相同,这就导致了同一种商品在不同城市的价格不一定相同。但是,同一种商品在同一个城市的买入价和卖出价始终是相同的。商人阿...原创 2019-08-24 10:40:51 · 201 阅读 · 0 评论 -
道路和航线(spfa+SLF)
题目描述Farmer John正在一个新的销售区域对他的牛奶销售方案进行调查。他想把牛奶送到T个城镇 (1 <= T <= 25,000),编号为1T。这些城镇之间通过R条道路 (1 <= R <= 50,000,编号为1到R) 和P条航线 (1 <= P <= 50,000,编号为1到P) 连接。每条道路i或者航线i连接城镇Ai (1 <= Ai &l...原创 2019-08-27 10:43:43 · 211 阅读 · 0 评论 -
Monitoring Ski Paths(dfs序+搜索)
题目描述Fresh powder on a sunny day: it is a great time to ski! Hardcore skiers flock to a large mountain in the Rockies to enjoy these perfect conditions. The only way up the mountain is by helicopter; ...原创 2019-08-30 09:48:22 · 266 阅读 · 4 评论 -
MEETING(完全图建图 最短路)
题目描述Bessie and her friend Elsie decide to have a meeting. However, after Farmer John decorated his fences they were separated into different blocks. John’s farm are divided into n blocks. Bessie live...原创 2019-10-04 00:59:19 · 288 阅读 · 0 评论 -
Star(图论)
题目描述有n个人参加Revue,她们之间共进行了m场比赛如果在某场比赛中a击败了b,那么a可能胜过b如果a可能胜过b,b可能胜过c,那么a可能胜过c如果x可能胜过y,y也可能胜过x,那么x和y是旗鼓相当的但如果x可能胜过y不满足,y可能胜过x也不满足,那么x和y不是旗鼓相当的可以发现,如果a和b是旗鼓相当的,b和c是旗鼓相当的,那么a和c也是旗鼓相当的。也就是说,若干个旗鼓相当的人组成...原创 2019-10-01 01:17:51 · 1174 阅读 · 0 评论 -
Cow Relays(矩阵快速幂 + floyd)
题目描述For their physical fitness program, N (2 ≤ N ≤ 1,000,000) cows have decided to run a relay race using the T (2 ≤ T ≤ 100) cow trails throughout the pasture.Each trail connects two different inte...原创 2019-09-20 15:51:22 · 405 阅读 · 0 评论