随笔分类 - 图论
摘要:1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const int N = 5e3 + 10; 5 ll dep[N], h[N], dis[N], vis[N], n, m, s, t, ans1
阅读全文
摘要:1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const int N = 1000; 5 ll dep[N], h[N], now[N],n, m, s, t, ee = 2; 6 7 struc
阅读全文
摘要:1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const int N = 5e3 + 10; 5 ll n, m, s, t, ans1, ans2, ee = 2; 6 ll flg[N][N]
阅读全文
摘要:1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const int N = 5e3 + 5; 5 ll n, m, s, t, ee = 2; 6 int flg[1000][1000], vis[
阅读全文
摘要:1 二分图: 2 可以把图上所有点分成两个点集,且每条边均不在同一个点集的图。 3 如果环为二分图,那么边数一定是偶边。 4 显然若起点在A集合,则从A集合出发的点都是奇数边,从B集合连出的边都是偶数边,成环的二分图必然是从B连回A的,故边数为偶数,这也证明的奇环不是二分图; 5 二分图成环一定是偶
阅读全文
摘要:1 class Solution { 2 public: 3 bool isBipartite(vector<vector<int>>& graph) { 4 int n=graph.size(); 5 vector<int>G[n],f(n,0); 6 for(int i=0;i<n;i++) 7
阅读全文
摘要:每次利用已经加入生成树的点集寻找未加入的点集的最小边,然后添加该点,并把minw[u]设置为最小生成树到u的最小距离; 证明算法正确性; 如果存在x1 x2均能联通到达生成树,其中若minw[x2]>minw[x1] 此时选x2加入生成树一定没有选X1优,正确性可以保证; 1 #include<bi
阅读全文
摘要:就是一种优化思想,基于搜索的思想,dijsktra堆优化也差不多是这样,只不过堆优化加了启发式选dis[u]较小的先更新,类似普通搜索与A*的区别;
阅读全文
摘要:1 #include<bits/stdc++.h> 2 using namespace std; 3 const int N=1e5+5; 4 int dis[N],n,m; 5 struct edge 6 { 7 int u,v,w; 8 }e[N]; 9 //对每条边进行松弛,每次松弛至少能更新
阅读全文
摘要:1 #include<bits/stdc++.h> 2 using namespace std; 3 const int N=105; 4 int n; 5 int in[N]; 6 vector<int>G[N]; 7 int main() 8 { 9 scanf("%d",&n); 10 que
阅读全文
摘要:P1546 [USACO3.1]最短网络 Agri-Net 1 #include<bits/stdc++.h> 2 using namespace std; 3 const int N=105; 4 int n,tot; 5 int fa[N]; 6 int read() 7 { 8 int x=0
阅读全文
摘要:题目后续补吧,主要解决问题; 1 #include<bits/stdc++.h> 2 using namespace std; 3 const int N=1e5+5; 4 int fa[N]; 5 int find_fa(int x){ 6 return fa[x]=(x==fa[x])?x:fi
阅读全文
摘要:1 #include<bits/stdc++.h> 2 using namespace std; 3 const int N=1e2+5; 4 int G[N][N]; 5 int main() 6 { 7 int n,m; 8 scanf("%d%d",&n,&m); 9 for(int i=1;
阅读全文
摘要:1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef pair<int,double>pii; 4 const int N=2005; 5 const double inf=1e-5; 6 int n,m,st,ed; 7 double
阅读全文
摘要:题目要求的是两个牧场的最小直径,数据给出不只是两个独立牧场而是至少两个 所以我们要去暴力枚举每个不属于同一牧场的直径的最小值 这里需要注意的是两个牧场连起来的直径不一定是连线后 i所在的最短路+j所在的最短路+dis(i,j); 例如 1 #include<bits/stdc++.h> 2 usin
阅读全文
摘要:1 class Solution { 2 public: 3 typedef pair<int,int> pii; 4 struct cmp{ 5 bool operator ()(pii &a,pii &b) 6 { 7 return a.second>b.second; 8 } 9 }; 10
阅读全文