并查集合并 #include<iostream> using namespace std; const int MAX = 10010; int father[MAX],root[MAX]; int findfather(int x){ if(x==father[x]) return x; else{ int F=findfather(father[x]); father[x]=F; return F; } } void Union(int a , int b){ int faA=findfa…
如题... #include <iostream> #include <cstdio> #include <algorithm> #include <string.h> using namespace std; /* 并查集水题 */ +; struct UF{ int father[maxn]; void init(){ ;i<maxn;i++) father[i]=i; } int find_root(int x){ if(father[x]!=x…
Some scientists took pictures of thousands of birds in a forest. Assume that all the birds appear in the same picture belong to the same tree. You are supposed to help the scientists to count the maximum number of trees in the forest, and for any pai…
题目链接 题解:并查集把一个家的并在一起,特殊的一点是编号大的并到小的去.这个题有个坑编号可能为0000,会错数据3和5. 1 #include<bits/stdc++.h> 2 using namespace std; 3 4 struct node 5 { 6 int id,num,area,fa,ma; 7 int ch[10]; 8 }p[100100]; 9 10 struct fz 11 { 12 int id,all; 13 double num,area; 14 }q[1001…
代码: 1 /* 2 这道题也是简单并查集,并查集复杂度: 3 空间复杂度为O(N),建立一个集合的时间复杂度为O(1),N次合并M查找的时间复杂度为O(M Alpha(N)), 4 这里Alpha是Ackerman函数的某个反函数,在很大的范围内(人类目前观测到的宇宙范围估算有10的80次方个原子, 5 这小于前面所说的范围)这个函数的值可以看成是不大于4的,所以并查集的操作可以看作是线性的. 6 7 不弄清楚一个算法的复杂度就是不敢很用 8 9 10 题解: 11 在询问时,标记当前结点,然…
题意: 输入一个正整数N(<=10000),接着输入N行数字每行包括一个正整数K和K个正整数,表示这K只鸟是同一棵树上的.输出最多可能有几棵树以及一共有多少只鸟.接着输入一个正整数Q,接着输入Q行每行包括两个正整数,输出它们是否在同一棵树上. AAAAAccepted code: #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; ]; ]; int find_(int x){ if(x==f…
A graph which is connected and acyclic can be considered a tree. The height of the tree depends on the selected root. Now you are supposed to find the root that results in a highest tree. Such a root is called the deepest root. Input Specification: E…
1118. Birds in Forest (25) Some scientists took pictures of thousands of birds in a forest. Assume that all the birds appear in the same picture belong to the same tree. You are supposed to help the scientists to count the maximum number of trees in…
1118 Birds in Forest (25 分) Some scientists took pictures of thousands of birds in a forest. Assume that all the birds appear in the same picture belong to the same tree. You are supposed to help the scientists to count the maximum number of trees in…
题目 This time, you are supposed to find A×B where A and B are two polynomials. Input Specification: Each input file contains one test case. Each case occupies 2 lines, and each line contains the information of a polynomial: K N​1​​ a​N​1​​ ​​ N​2​​ a​…