Tips: 这种数据如果没有路径压缩的话是很容易超时的。 5001 2 1 2 2 3 4 2 5 6 …… 2 9997 9998 2 9999 10000 5000 1 3 5 …… 9997 9999 10000 10000 10000 …… 10000 10000 ${O_{\left( n ...
分类:
其他好文 时间:
2020-03-17 12:42:21
阅读次数:
61
tarjan算法:离线处理询问,核心思想是并查集。 如该图,现有4个询问:6-7,6-9,7-10,2-11 实现:1.先把询问数翻倍,除了本身的询问,还要增加两个点反过来的询问,即7-6,9-6,10-7,11-2。为什么要这样?因为在询问时,不知道两个点的先后顺序。 2.从根结点出发,做dfs遍 ...
分类:
其他好文 时间:
2020-03-17 12:41:50
阅读次数:
69
一、场景 并查集多数是用来解决连通性问题的 如至少修建几条路可以使所有路口可以相通 把互通的路口当做一个群组,那问题就是有几个这样的群组 如有N个群组 那至少修N-1条路 就可以把所有路口相连。 二、使用 并查集分两步 1、合并 合并就是把相连的多个节点划到一个群组中 可以定义数组parent[] ...
分类:
其他好文 时间:
2020-03-16 23:47:39
阅读次数:
87
int superior[MAXN]; int find_root(int son) { // int temp=son; // while(son!=superior[son]) // son=superior [son]; // superior[temp]=son;//路径压缩 // retu ...
分类:
其他好文 时间:
2020-03-15 13:29:04
阅读次数:
40
并查集 #include<iostream> #include<string.h> #include<algorithm> #include<cmath> #include<map> #include<string> #include<stdio.h> #include<vector> #inclu ...
分类:
其他好文 时间:
2020-03-15 00:15:07
阅读次数:
61
#include <cstdio> #include <iostream> #include <cmath> #include <cstdlib> #include <cstring> #define _for(i,a,b) for(int i= a;i<b;i++) using namespace ...
分类:
Web程序 时间:
2020-03-15 00:00:17
阅读次数:
65
题目链接: "P2342 [USACO04OPEN]Cube Stacking G" 双倍经验: "P5092 [USACO04OPEN]Cube Stacking" 裸的加权并查集,直接维护下就好了,不过还是犯了$SB$错误,和$lhr$大佬一起沦为$18\;\;pts$。 在询问的时候同步更新一 ...
分类:
其他好文 时间:
2020-03-14 20:24:23
阅读次数:
56
"AtCoder Beginner Contest 157" B $and,not,or$ 这些关键字比较好打 这题加个标记数组就好 ...
分类:
其他好文 时间:
2020-03-14 12:35:56
阅读次数:
44
基本思想: 无; 关键点: 无; #include<iostream> #include<string> #include<vector> #include<algorithm> #include<set> using namespace std; const int maxn = 1000000; ...
分类:
其他好文 时间:
2020-03-14 01:12:51
阅读次数:
56
有一类并查集题目中,起始是一张连了所有边的图。 给出一些操作,让一些边"断裂",再抛出一些问题。 这个时候,就可以考虑逆向合并边。 例题星球大战:https://www.luogu.com.cn/problem/P1197 思路: 因为每次轰炸星球,相当于把一个点完全抹除,相应的边也没了。 那么我们 ...
分类:
其他好文 时间:
2020-03-12 14:24:15
阅读次数:
54