随笔分类 -  图论

摘要:https://www.acwing.com/problem/content/submission/code_detail/4121247/ 知识点 #include <bits/stdc++.h> using namespace std; #define IO ios::sync_with_std 阅读全文
posted @ 2021-02-24 21:04 phr2000 阅读(52) 评论(0) 推荐(0)
摘要:捉迷藏 最小路径重复点覆盖 #include <bits/stdc++.h> using namespace std; #define IO ios::sync_with_stdio(false);cin.tie(0); cout.tie(0) inline int lowbit(int x) { 阅读全文
posted @ 2021-02-22 17:11 phr2000 阅读(117) 评论(0) 推荐(0)
摘要:骑士放置 最大独立集 #include <bits/stdc++.h> using namespace std; #define IO ios::sync_with_stdio(false);cin.tie(0); cout.tie(0) inline int lowbit(int x) { ret 阅读全文
posted @ 2021-02-22 17:09 phr2000 阅读(63) 评论(0) 推荐(0)
摘要:机器任务 最小点覆盖 #include <bits/stdc++.h> using namespace std; #define IO ios::sync_with_stdio(false);cin.tie(0); cout.tie(0) inline int lowbit(int x) { ret 阅读全文
posted @ 2021-02-22 17:07 phr2000 阅读(49) 评论(0) 推荐(0)
摘要:棋盘覆盖 匈牙利算法 #include <bits/stdc++.h> using namespace std; #define IO ios::sync_with_stdio(false);cin.tie(0); cout.tie(0) inline int lowbit(int x) { ret 阅读全文
posted @ 2021-02-22 17:05 phr2000 阅读(56) 评论(0) 推荐(0)
摘要:关押罪犯 #include <bits/stdc++.h> using namespace std; #define IO ios::sync_with_stdio(false);cin.tie(0); cout.tie(0) inline int lowbit(int x) { return x 阅读全文
posted @ 2021-02-22 17:03 phr2000 阅读(87) 评论(0) 推荐(0)
摘要:闇の連鎖 \(\color{Red}{本题的实质是看一条边属于几个环}\) \(如图, 如何使标记的边的覆盖次数+c ?\) \(我们把边权看成是其子树下所有点权之和,如果我需要增加x到p与y到p之间的边权,p=lca(x,y),\\那么只需要将x标记为x+c,y标记为y+c,p标记为p-2c\) 阅读全文
posted @ 2021-02-19 16:31 phr2000 阅读(69) 评论(0) 推荐(0)
摘要:\(Tarjan\ O(m + n)\) \(Tarjan为离线算法\) \(在线做法:边读边做\) \(离线做法:先读完,再全部处理,最后全部输出\) \(Tarjan本质上是对向上标记法的优化,首先任取一个点当成根节点向下做dfs,并将所有节点分为三部分\) \(已经遍历并完成了回溯的点标记为2 阅读全文
posted @ 2021-02-18 21:45 phr2000 阅读(88) 评论(0) 推荐(0)
摘要:最近公共祖先 \((1)向上标记法\ O(n)\) \((2)倍增:fa[i,j]表示从i开始,向上走2^j步所能走到的节点,0 \le j\le log_2n,depth[i]表示深度\) \(步骤\) \(先将两个点跳到同一层\) \(让两个点同时往上跳,一直跳到它们的最近公共祖先的下一层\) 阅读全文
posted @ 2021-02-18 14:12 phr2000 阅读(69) 评论(0) 推荐(0)
摘要:\((1)求不等式的可行解\\ 源点需要满足的条件: \color{Red}{从源点出发,一定可以走到所有的边.}\) 步骤 \(先将每个不等式x_i\le x_j + c_k,转化为一条从x_j走到x_i,长度为c的一条路径.\) \(找一个虚拟源点,使得该源点一定可以遍历所有边.\) \(从源点 阅读全文
posted @ 2021-02-18 00:53 phr2000 阅读(39) 评论(0) 推荐(0)
摘要:雇佣收银员 分析 \(本题令s_i为0\sim i点需要的人数和\) \(\color{Red}{s_i作为图中的点}\) \(为了方便使用前缀和,r_i统一往后错一位,于是r_i表示i-1\sim i中需要的人数\) \(因为24小时是一个环的形式,这里的前缀需要注意:\) \(0\sim7小时间 阅读全文
posted @ 2021-02-18 00:51 phr2000 阅读(43) 评论(0) 推荐(0)
摘要:排队布局 分析 \(第一问问是否存在负环,将n个点全放进队列即可\) \(如何判断1到N的距离可以无限大?\) \(即判断1到N是否连通.\) 约束关系 \(x_b\le x_a+L\) \(x_b-x_a\ge D\Rightarrow x_a\le x_b-D\) \(x_i\le x_{i+1 阅读全文
posted @ 2021-02-17 22:45 phr2000 阅读(57) 评论(0) 推荐(0)
摘要:区间 分析 \(前缀和 + 差分约束\) \(令S_i为1\sim i中被选出的数.\) 约束关系 \(S_i \ge S_{i-1}\) \(S_i-S_{i-1}\le 1\Rightarrow S_{i-1}\ge S_i-1\) \(S_a-S_b\ge c\) 代码 #include <b 阅读全文
posted @ 2021-02-17 20:30 phr2000 阅读(61) 评论(0) 推荐(0)
摘要:糖果 分析 \(要求糖果的最小值,应该把不等式处理成x_i \ge x_j+c的形式,求最长路.\) 约束关系 \(x_i \ge 1\) \(x_i\ge x_0+1\) \(x_0=0\) \(当负环导致TLE,可以尝试将queue换成stack.\) #include <bits/stdc++ 阅读全文
posted @ 2021-02-17 17:09 phr2000 阅读(61) 评论(0) 推荐(0)
摘要:观光奶牛 \(求负环 + 01分数规划\) 思路 \(将点权算入边权:\) \[ \begin{aligned} &\frac{\sum{f_i}}{\sum{w_i}}>mid\\ \Rightarrow\ &\sum{f_i}-\sum{w_i}*mid>0\\ \Rightarrow\ &\s 阅读全文
posted @ 2021-02-16 21:08 phr2000 阅读(61) 评论(0) 推荐(0)
摘要:虫洞 \(本题为裸题\) 求负环 \(基于spfa\) \((1)统计每个点入队的次数,如果某个点入队n次,则说明存在负环.\) $(2)统计每个点的最短路中所包含的边数,如果某点的最短路所包含的边数大于等于n,\则也说明存在负环.\$ \(对于求负环是否存在,dist的初始化是无所谓的.\) #i 阅读全文
posted @ 2021-02-16 20:47 phr2000 阅读(94) 评论(0) 推荐(0)
摘要:https://www.acwing.com/problem/content/1148/ #include <bits/stdc++.h> using namespace std; #define IO ios::sync_with_stdio(false);cin.tie(0); cout.tie 阅读全文
posted @ 2021-02-15 17:32 phr2000 阅读(61) 评论(0) 推荐(0)
摘要:https://www.acwing.com/problem/content/1150/ 次小生成树 \(定义:给一个带权的图,把图的所有生成树按权值从小到大排序,第二小的称为次小生成树.\) 求法 \(方法1:先求最小生成树,再枚举删去最小生成树的边求解,时间复杂度\ O(mlogm + nm). 阅读全文
posted @ 2021-02-15 17:07 phr2000 阅读(62) 评论(0) 推荐(0)
摘要:https://www.acwing.com/problem/content/1145/ 思路 \(把已有的边加上,会形成各个连通块,等价于把每个连通块当成一个点去做Kruskal算法.\) #include <bits/stdc++.h> using namespace std; #define 阅读全文
posted @ 2021-02-14 23:04 phr2000 阅读(46) 评论(0) 推荐(0)
摘要:https://www.acwing.com/problem/content/1144/ #include <bits/stdc++.h> using namespace std; #define IO ios::sync_with_stdio(false);cin.tie(0); cout.tie 阅读全文
posted @ 2021-02-14 23:01 phr2000 阅读(68) 评论(0) 推荐(0)