随笔 - 531  文章 - 0  评论 - 3  阅读 - 10215 

随笔分类 -  图论

欧拉路 笔记
摘要:A.对于欧拉路径: 有向图:图连通,有一个顶点出度大入度1,有一个顶点入度大出度1,其余都是出度 == 入度 无向图:图连通,只有两个顶点是奇数度,其余都是偶数度 B.对于欧拉回路: 有向图:图连通,所有的顶点出度 == 入度 无向图:图连通,所有顶点都是偶数度 阅读全文
posted @ 2023-02-18 15:09 towboat 阅读(14) 评论(0) 推荐(0) 编辑
判负环
摘要:看 某个点的入队次数 times>=n #include <bits/stdc++.h> using namespace std ; const int N=1e5+2,inf=0x7f7f3f; struct E{ int y,z; E(int y0,int z0){ y=y0,z=z0; } f 阅读全文
posted @ 2023-02-17 22:54 towboat 阅读(14) 评论(0) 推荐(0) 编辑
图论 记录
摘要:// 阅读全文
posted @ 2022-12-21 11:17 towboat 阅读(10) 评论(0) 推荐(0) 编辑
一本通1525:电力
摘要:给一个图,删除一个点,问最多得到多少个块 当low[y]>dfn[x] ,发现一个割点时,删去这个点会出现新的块 ans =原来的块的个数+ 删点产生的块 #include <bits/stdc++.h> using namespace std ; const int N=1e5+1,M=5*N; 阅读全文
posted @ 2022-11-26 20:26 towboat 阅读(68) 评论(0) 推荐(0) 编辑
1523:嗅探器
摘要:找割点,且去掉这个点后 S,T 两个点在2个块中 除了dfn[x]<=low[y] , 还有 dfn[y]<=dfn[T ] #include <bits/stdc++.h> using namespace std ; const int N=2*1e5+1,M=5*1e5+1; int nxt[M 阅读全文
posted @ 2022-11-26 18:15 towboat 阅读(94) 评论(0) 推荐(0) 编辑
1520:【 例 1】分离的路径
摘要:给一张图加边成为双连通分量( 任意两点之间都有两条不重叠的道路) 缩点得到树,ans= (leaf_num+1)/2 一条无向边只走一次 (flag==0) #include <bits/stdc++.h> using namespace std ; const int N=6000,M=7*1e4 阅读全文
posted @ 2022-11-26 17:44 towboat 阅读(103) 评论(0) 推荐(0) 编辑
一本通 1521: 矿场搭建
摘要:给一个无向图,选择一些点,使得任意去掉一个点后,任一点都可以连接到至少一个选择的点 缩点后,每个块: 1. 割点数量为0, 要建立2个站点, 方案+= len(len-1) 2. 数量为1,建立1个站点 方案+=len-1 #include <bits/stdc++.h> using namespa 阅读全文
posted @ 2022-11-26 12:05 towboat 阅读(79) 评论(0) 推荐(0) 编辑
割点/边 板子
摘要:一些直白的理解,和标准定义有差别,但也足够了 点双连通:一个图任意去掉一个点后仍然联通( 或者说任意两点件都有两条路径(无任何重叠的边) ) ; 边双连通同理 割点:去掉某个点后,图不连通 割边同理 求割点 ( low[y]>=dfn[x] ) #include <bits/stdc++.h> us 阅读全文
posted @ 2022-11-26 11:57 towboat 阅读(28) 评论(0) 推荐(0) 编辑
P3627 [APIO2009] 抢掠计划
摘要:从起点S到终点T,求一条路线获得最多的收益( 每个点收益a[i] ) , 可以重复通过路和点 裸题 缩点+最长路 #include <bits/stdc++.h> using namespace std ; const int N=5e5+2; int n,m,pool,a[N]; int low[ 阅读全文
posted @ 2022-11-26 01:12 towboat 阅读(25) 评论(0) 推荐(0) 编辑
P3387 缩点
摘要:缩点求DAG最长路 tarjan缩点:给一个强连通分量内的点打标记,缩为新的点,建立新的图( DAG ) #include <bits/stdc++.h> using namespace std ; const int N=1e4+2; int n,m,a[N]; int pool,low[N],d 阅读全文
posted @ 2022-11-25 23:33 towboat 阅读(20) 评论(0) 推荐(0) 编辑
P2341 [HAOI2006] 受欢迎的牛 G
摘要:每头奶牛都梦想成为牛棚里的明星。被所有奶牛喜欢的奶牛就是一头明星奶牛。 每头奶牛总是喜欢自己的。奶牛之间的“喜欢”是可以传递的 问有多少头奶牛可以当明星 缩点为DAG, 求出度为0的点 #include <bits/stdc++.h> using namespace std ; const int 阅读全文
posted @ 2022-11-25 23:22 towboat 阅读(17) 评论(0) 推荐(0) 编辑
#10078. 「一本通 3.2 练习 4」新年好
摘要:从1出发访问 5个给定点,最小化路程 枚举5个点的排列,然后单源最短路 #include <iostream> #include <cstring> #include <queue> using namespace std ; struct T{ int y,z; T(int y0,int z0){ 阅读全文
posted @ 2022-11-12 12:43 towboat 阅读(40) 评论(0) 推荐(0) 编辑
P2865 [USACO06NOV]Roadblocks G
摘要:求1到n的 次短路 #include <iostream> #include <cstring> #include <queue> using namespace std ; const int N=1e6+2,M=5e6+2; const int inf=0x3f3f3f3f; int all,n 阅读全文
posted @ 2022-11-12 10:56 towboat 阅读(14) 评论(0) 推荐(0) 编辑
#10077. 「一本通 3.2 练习 3」最短路计数
摘要:问1~n的最短路有几个 #include <iostream> #include <cstring> #include <queue> using namespace std ; const int N=1e6+2,M=2e6+2; const int inf=0x3f3f3f3f,mod=1000 阅读全文
posted @ 2022-11-12 10:21 towboat 阅读(40) 评论(0) 推荐(0) 编辑
#10075. 「一本通 3.2 练习 1」农场派对
摘要:图上每个点有一头牛,现在牛群聚集到点X上聚会,然后又回到各自的点,而且牛只走最短路径 问所有最短路中最长的一条( 路径包含来回) 正反跑一次 spfa(X) , spfa(i) , ans=max{ d0[i]+ dis[X] } #include <iostream> #include <cstr 阅读全文
posted @ 2022-11-12 09:54 towboat 阅读(50) 评论(0) 推荐(0) 编辑
#10074. 「一本通 3.2 例 3」架设电话线
摘要:在加权无向图上求出一条从 1 号结点到 N 号结点的路径,使路径上第 K + 1 大的边权尽量小 二分答案md, 判断1~n是否存在一条路径,花费不超过md 把w<=md 的边看作0,否则看作1,求1到n 的最短路,看 dis[n]<=md #include <bits/stdc++.h> usin 阅读全文
posted @ 2022-11-12 09:15 towboat 阅读(90) 评论(0) 推荐(0) 编辑
loj #10069. 「一本通 3.1 练习 4」Tree
摘要:给你一个无向带权连通图,每条边是黑色或白色。求一棵最小权的恰好有 K 条白色边的生成树。题目保证有解 二分一个增加量md, 给每个白边权值加md , 跑一下kruskal , 看贪心取了多少白边,和K比较检验答案 #include <bits/stdc++.h> using namespace st 阅读全文
posted @ 2022-11-11 17:34 towboat 阅读(42) 评论(0) 推荐(0) 编辑
#10067. 「一本通 3.1 练习 2」构造完全图
摘要:给一颗最小生成树,构造一个权和最小的完全图 无疑是贪心,模仿kruskal 做法 考虑一条树边,它连接了两个块,在块之间的连线中是最小的,构造完全图后,考虑所有这些连线,权值应该为 w+1 #include <bits/stdc++.h> using namespace std ; const in 阅读全文
posted @ 2022-11-11 15:33 towboat 阅读(41) 评论(0) 推荐(0) 编辑
loj#10064 黑暗城堡
摘要:求图中的最短路径生成树有多少个? ( 该生成树中的任意点i ,i到1的距离和 原图中的i到1的最短距离相等 跑所有点到1的单源最短路,d[i] if d[i]==d[y]+z ,那么z这个路径是该生成树的一条边 然后就是多步计数,乘法原理即可 #include <iostream> #include 阅读全文
posted @ 2022-11-11 13:34 towboat 阅读(16) 评论(0) 推荐(0) 编辑
最短路板子
摘要:floyed O(n^3) f[i][j] = min(f[i][j] ,f[i][k] + f[k][j] ) memset(f,inf,sizeof(f)); for(i=1;i<=m;i++) cin>>x>>y>>z,f[x][y]=f[y][x]=z; for(k=1;k<=n;k++) 阅读全文
posted @ 2022-11-11 12:53 towboat 阅读(18) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示