-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathset_union.h
43 lines (28 loc) · 1.08 KB
/
set_union.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/* set_union.h
Header file for union-find data structure implementation
by: Steven Skiena
*/
/*
Copyright 2003 by Steven S. Skiena; all rights reserved.
Permission is granted for use in non-commerical applications
provided this copyright notice remains intact and unchanged.
This program appears in my book:
"Programming Challenges: The Programming Contest Training Manual"
by Steven Skiena and Miguel Revilla, Springer-Verlag, New York 2003.
See our website www.programming-challenges.com for additional information.
This book can be ordered from Amazon.com at
http://www.amazon.com/exec/obidos/ASIN/0387001638/thealgorithmrepo/
*/
#include "bool.h"
#define SET_SIZE 1000
/* [[[ set_union_cut */
typedef struct {
int p[SET_SIZE+1]; /* parent element */
int size[SET_SIZE+1]; /* number of elements in subtree i */
int n; /* number of elements in set */
} set_union;
/* ]]] */
void set_union_init(set_union *s, int n);
void union_sets(set_union *s, int s1, int s2);
bool same_component(set_union *s, int s1, int s2);
void print_set_union(set_union *s);