摘要:
这道题根同性恋那道题相当像无非就是看他有没有合并过、记录合并之后的那个点的关系罢了。View Code //AC代码1#include <stdio.h> #include <stdlib.h> int set[100005],num[100006],h[100005]; int find(int x) { if(x!=set[x]) { int y = set[x]; set[x] = find(set[x]); num[x] = (num[x]+num[y])%2;//一定要写这个%2不知道为什么不加%2他就wa加上就ac我郁... 阅读全文
摘要:
首先看到这个题号的时候我想起了好公民,韩寒同学和他的不死鸟= =本人二蛋一枚,近日做了些并查集的东西但是一直不太明白怎么才能查节点路径,而且觉得要是迭代的时候加了r[x]的话会出现多加的情况,后来经网上高人指点(觉得还是好人多,虽然自己确实不想做好人了= =)明白了~一下是高人话语~voidmerge(int a,int b){ father[a]=b; place[a]+=number[b]; number[b]+=number[a];}intFind(int a)//检查找和路径压缩{if(father[a]==-1)return a;int tmp=father[a];... 阅读全文
摘要:
跟那个排序二叉树的那个静态树一样,不大习惯静态的,但是不静态会tle,94msView Code #include<stdio.h>#include<stdlib.h>#include<string.h>typedef struct node{ int flag; int next[11];}trie;int leap,count;trie tr[100010];new_node(){ int i; count++; tr[count].flag = 0; for(i = 0;i < 10;i++) tr[count].next[i] ... 阅读全文