- 博客(13)
- 收藏
- 关注
原创 Tarjan 算法理解及模板
Tarjan算法Tarjan算法思路不难理解,因为任何一个强连通分量,必定是对原图的深度优先搜索树的子树。那么其实只要确定每个强连通分量的子树的根,然后根据这些根从树的最低层开始,一个一个的拿出强连通分量即可。那么剩下的问题就只剩下如何确定强连通分量的根和如何从最低层开始拿出强连通分量了。那么如何确定强连通分量的根,在这里我们维护两个数组,一个是indx[1…n],一个是mlik[1…n],其中indx[i]表示顶点i开始访问时间,mlik[i]为与顶点i邻接的顶点未删除顶点j的mlik[j]和mlik
2021-12-08 20:30:46
585
原创 计蒜客题目 单词拼接
#include<bits/stdc++.h>using namespace std;const int maxn=1e6+7;struct { int v; int next;}e[maxn];int n;int cnt=0;int head[30];int idegree[30];int odegree[30];int vis[30];int vis1[30];void add(int u,int v){ e[cnt].v=v; e[cnt].next=hea
2021-12-08 14:32:56
420
原创 计蒜客 布设光纤
#include<bits/stdc++.h>using namespace std;int n;const int maxn=1e5+7;struct edge{ int u,v,w;};edge e[maxn];int father[105];bool cmp(edge a,edge b){ return a.w<b.w;}int get(int x){ if(father[x]==x) return x; else return father[x]=get
2021-12-06 21:16:58
739
原创 计蒜客 穿越雷区
#include<bits/stdc++.h>using namespace std;int n,m;const int maxn=1e5+7;int father[maxn];struct edge{ int u,v,w;}e[maxn];bool cmp(edge a,edge b){ return a.w<b.w;}int get(int a){ if(father[a]==a) return a; else return father[a]=get(fat
2021-12-06 21:15:54
103
原创 计蒜客 高速公路
#include<bits/stdc++.h>using namespace std;int n,m;bool flag=false;int minn=0x3f3f3f3f;const int maxn=1e5+7;int father[maxn];struct edge{ int u,v,w;}e[maxn];bool cmp(edge a,edge b){ return a.w<b.w;}int get(int a){ if(father[a]==a) re
2021-12-06 21:15:18
436
原创 计蒜客 节点最近公共祖先
#include<bits/stdc++.h>using namespace std;const int maxn=1e5+7;struct edge{ int v,next;}e[maxn];int n;int q;int pre[maxn][23];int d[maxn];int head[maxn];int cnt=0;int father[maxn];void add(int u,int v){ e[cnt].v=v; e[cnt].next=head[u]
2021-12-06 21:14:11
114
原创 计蒜客 欧拉回路
#include<bits/stdc++.h>using namespace std;int n,m;const int maxn=1e3+5;const int MAX=1e5+6;int degree[maxn];int head[maxn];int vis[maxn];struct { int v,next;}e[MAX<<1];int cnt=0;void add(int u,int v){ e[cnt].v=v; e[cnt].next=head
2021-12-06 21:12:13
65
原创 有向图中欧拉回路存在的充分条件及证明
有向图中欧拉回路存在的充分条件:有向图为连通图,且每个点的入度和出度是相等的证明:证明方法为构造性证明过程:任意选取一点v作为起始点,遍历其能到达的点,找到一条回路(这里设该回路为R1),可以证明以v为起点一定存在一条回路(证明:假设v能到达点u,由于图为连通图,那么u一定也能找到一条能够到达v的路径,这条路径即为一条回路)。在这条回路中,若存在点p,连接到p的出边不在该回路中,那么由于p点在回路R1中的入边数量一定等于在回路R1中的出边数量,因此p点不在该回路中的入边数量也等于不在该回路中的出边数量,
2021-11-23 20:18:24
4434
转载 证明定理的方法归纳
证明定理的方法主要归纳为以下几种:1)直接证明:通过证明当 p 为真时 q 必然为真而进行的对 p->q 的证明。2)反证法:反证法是一种间接证明方法,利用条件语句 p->q 等价于它的倒置 ¬q->¬p 的事实,换句话说,就是通过证明 q 是假时 p 一定是假来证明 p->q 为真。当不容易找到直接证明时用反证会很有效。在反证中,要假设条件语句的结论为假,并使用直接证明法表明这意味着前提必为假。3)归谬证明:归谬证明也是一种间接证明方法,假设我们想证明 p 是真的,假定可以找
2021-11-23 15:47:16
2148
原创 计蒜客题目 货车运输
#include<bits/stdc++.h>using namespace std;const int maxn=1e5+7;struct edge{ int u,v,w,next;}e[maxn];edge e1[maxn];int cnt=0;int n,m,q;int head[maxn];int pre[maxn][23];int d[maxn];int dist[maxn][23];bool cmp(edge a,edge b){ return a.w&g
2021-11-22 20:47:10
275
原创 计蒜客题目 威虎山上的分配
#include<bits/stdc++.h>using namespace std;int n,m;const int maxn=1e5+7;int head[maxn];int degree[maxn];int p[maxn];struct { int v,next;}e[maxn];int cnt;void add(int u,int v){ e[cnt].v=v; e[cnt].next=head[u]; head[u]=cnt++;}queue<i
2021-11-22 20:46:32
744
原创 计蒜客拓扑排序题目 回收元件
#include<bits/stdc++.h>using namespace std;struct node{int x1,y1,x2,y2;};int n;const int maxn=1e4+7;const int MAX=1e6+7;node it[maxn];struct edge{int v,next;}e[MAX<<3];int cnt=0;int head[maxn];void add(int u,int v){e[cnt].v=v;e[
2021-11-22 20:44:15
714
原创 Kruskal最小生成树算法的证明
记录下自己对kruskal算法正确性的理解一步一步证明:首先,对于每个点vi,连接到这个点的所有边中最短的一条边一定属于最小生成树。证明:假设(vi,vj)为连接到vi所有边中的最短边。假设最小生成树已经建好,那么我们可以将vi从图中取出,并断开vi与剩余部分相连的所有边。剩余的部分被分为若干个连通子图。此时重新将vi连接到剩余部分中,若想重新生成最小生成树,那么与vi相连的最短边必定会被连接,结论得证。其次,对于最小生成树的一个连通子图,连接到该连通子图的所有边中最短的一条边一定属于最小生成树。
2021-11-09 16:08:41
691
1
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人