并查集

https://codeforces.com/contest/2064/problem/E 题目大意 给出 $n$ 长的排列 $p$ 和 $n$ 长的颜色数组 $c$。从上到下,从 $i = 1 \sim n$ 将 $p_i$ 个颜色为 $c_i$ 的左侧对齐横向排列,之后让其按照重力规则下落,问有多少个不同的排列和颜色方案的二元组,可以得到和题目给出的排列颜色
https://codeforces.com/contest/2060/problem/E 题目大意 给出无向图 $F$ 和 $G$。可以对 F 进行操作:增加一条边或删除一条边的操作。 问至少需要多少次使得 $F$ 中任意两点 $u, v$ 有路径当且仅当 $G$ 中对应两点有路径。 给出 $F$ 和 $G$ 的点数 $n \ (\le 2 \times 10^5)$ 和各自的边数 $m_1, m_2 \ (0 \le
并查集 Union Find / Disjoint Set Union 路径压缩和按 size 合并 Union by Size // M: max number of set // id is in [0~M-1] template<size_t M> struct UF { int uf[M],sz[M]; int n; int ns; // number of set void init(int n_) { n=ns=n_; for(int i=0;i<n;i++) uf[i]=i,sz[i]=1; } int find(int x) { return x==uf[x]?x:uf[x]=find(uf[x]); } bool same(int x,int y) { return find(x)==find(y); } bool merge(int x,int y) { x=find(x); y=find(y); if(x==y) return false; if(sz[x]>sz[y]) swap(x,y); sz[y]+=sz[x]; uf[x]=y; ns--; return true; } }; Debug: void show() { cerr<<"UnionFind:----------------------\n"; cerr<<"id:"; for(int i=0;i<n;i++) cerr<<'\t'<<i; cerr<<'\n';
比赛简述 ABC 中比较简单的一场,题目也都比较常规 AtCoder Beginner Contest 177 A - Don’t be late 代码实现 #include <bits/stdc++.h>using namespace std; int main() { int d,t,s; scanf("%d%d%d",&d,&t,&s); printf("%s\n",t*s>=d ? "Yes" : "No"); return 0; } B - Substring 题目大意 给出两个串 $S$ 和 $T$,问 $S$ 至少替换多少字符可以使 $T$ 是 $S$ 的子串。 Tag: 暴力 简要题解 $S$ $T$