#include<stdio.h> #define N 1100000 struct node { int x,y; }f[N],pre[N]; int find(int x) { if(x!=pre[x].x) { int h=pre[x].x; pre[x].x=find(h); pre[x].y=(pre[x].y+pre[h].y)%2; } return pre[x].x; } int main() { int t,m,n,i,j,k,flag,cou=0; scanf("…
这道题我拖了有8个月... 今天放假拉出来研究一下带权的正确性,还有半开半闭的处理还有ab指向的一系列细节问题 #include<iostream> #include<algorithm> #include<cstdio> #include<cstring> using namespace std; const int maxn = 200010; int p[maxn],r[maxn]; void init(int n){ memset(r,0,sizeo…
#include<stdio.h> #include<string.h> #define N  200100 struct node { int x,count; }pre[N]; int find(int n) { if(n!=pre[n].x) { int h=pre[n].x; pre[n].x=find(pre[n].x); pre[n].count=pre[n].count+pre[h].count; } return pre[n].x; } int Union(int…
#include<iostream> #include<cstring> #include<cstdio> using namespace std; +; int p[N]; int w[N]; int find(int x) { if(p[x]==x) return x; int root=find(p[x]); w[x]+=w[p[x]]; p[x]=root; return p[x]; } int n,m; int main() { while(~scanf(&q…
Background Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes that they feature two different genders and that they only interact with bugs of the opposite gender. In his experiment, individual bugs and their in…
A Bug's Life Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 8528    Accepted Submission(s): 2745 Problem Description Background  Professor Hopper is researching the sexual behavior of a rare…
Travel Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5441 Description Jack likes to travel around the world, but he doesn’t like to wait. Now, he is traveling in the Undirected Kingdom. There are n cities and m…
http://acm.hdu.edu.cn/showproblem.php?pid=3047 题意: 给出n个座位,有m次询问,每次a,b,d表示b要在a右边d个位置处,问有几个询问是错误的. 思路: 基础带权并查集. #include<iostream> #include<cstdio> using namespace std; +; int n,m; int p[maxn],r[maxn]; int finds(int x) { if(p[x]==x) return x; in…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3038 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem Description TT and FF are ... friends. Uh... very very good friends -________-b FF is a bad boy, he is always…
传送门 The Experience of Love Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 221    Accepted Submission(s): 91 Problem Description A girl named Gorwin and a boy named Vivin is a couple. They arriv…