
并查集
ToheartZhang
这个作者很懒,什么都没留下…
展开
-
CODEVS 1074 食物链
//用三倍并查集表示三种动物,根据描述去找根,相邻关系为左吃右。无需确定具体ABC,只要关系定了即可。 #include<cstdio>#include<iostream>using namespace std;const int maxn = 50003;int f[3*maxn];int Find(int a){ if(f[a] == a) return a; re原创 2017-04-26 19:48:24 · 305 阅读 · 0 评论 -
NOIP2013 Day1 T3 货车运输
估计30分实际只有25分的SPFA求瓶颈路暴力#include<cstdio>#include<cstring>#include<queue>#include<iostream>using namespace std;const int inf = 100001;const int maxn = 10010;const int maxm = 50050;int n, m, q, to原创 2017-07-21 20:26:49 · 502 阅读 · 0 评论 -
洛谷 1196 银河英雄传说
#include<bits/stdc++.h>using namespace std;const int maxn = 30030;int t, fa[maxn], siz[maxn], dis[maxn];inline void init(){ for(int i = 0; i <= maxn; i++){ fa[i] = i; siz[i] = 1;原创 2017-08-10 15:40:08 · 443 阅读 · 0 评论 -
NOI 2015 程序自动分析
//要先处理=再判断!= //离散化后并的是地址而非数值 //low_bound可查询特定数值所在的地址,和map差不多?//思考查找其他离散化的方法 #include<bits/stdc++.h>using namespace std;const int maxn = 100010;int n, t, tot;int f[2*maxn], e[2*maxn];struct nod原创 2017-08-22 20:24:28 · 313 阅读 · 0 评论 -
洛谷 2024 食物链
//对于某种特定的动物,世界上只有三种动物,同类、他吃的和吃他的,按三类的关系维护并查集即可,注意要三类转移,而不仅转移当前动物的 。 //i+n吃i,i+2*n吃i+n, i吃i+2*n #include<bits/stdc++.h>using namespace std;const int maxn = 50010;int n, k, ans;int f[3*maxn];inline原创 2017-08-23 21:57:44 · 359 阅读 · 0 评论 -
模板大集结!
好久不碰OI了,最近决定把各种基础算法的模板和用法整理下。·SPFA -求瓶颈路 洛谷 1396 -求最短路 好多。。 -路上最值 洛谷 1073 -边的特殊处理 eg. 加入点出点 暑末Day2 T1 -判负环 可结合分数规划食用#include<bits/stdc++.h>using namespace std;const int maxn =原创 2017-09-09 21:52:57 · 341 阅读 · 0 评论 -
1.1 并查集 & 最小生成树
1.1.1 并查集用以表示某些关系,包括在同一集合,在对立集合等。**Eg1.洛谷1196 银河英雄传说** 加权并查集。不仅要知道两点有没有关系,还要具体知道两点之间的点数量。因此需要siz[]维护祖先旗下的点的数量,dis[]维护到队头的数量。询问时输出abs(dis[x]-dis[y])-1即可。#include<bits/stdc++.h>using namespace std原创 2017-11-06 08:19:47 · 313 阅读 · 0 评论