@@ -14,41 +14,38 @@ typedef vector<int> vi;
1414#include " ../../content/data-structures/UnionFind.h"
1515
1616int main () {
17- int s = (int )time (0 );
18- cout << s << endl;
19- srand (s);
20- for (;;) {
17+ srand (2 );
18+ LinkCut lczero (0 );
19+ rep (it,0 ,10000 ) {
2120 int N = rand () % 20 + 1 ;
22- rep (it,0 ,1000 ) {
23- LinkCut lc (N);
24- UF uf (N);
25- vector<pii> edges;
26- rep (it2,0 ,1000 ) {
27- int v = (rand () >> 4 ) & 3 ;
28- if (v == 0 && !edges.empty ()) { // remove
29- int r = (rand () >> 4 ) % sz (edges);
30- pii ed = edges[r];
31- swap (edges[r], edges.back ());
32- edges.pop_back ();
33- if (rand () & 16 )
34- lc.cut (ed.first , ed.second );
35- else
36- lc.cut (ed.second , ed.first );
21+ LinkCut lc (N);
22+ UF uf (N);
23+ vector<pii> edges;
24+ rep (it2,0 ,1000 ) {
25+ int v = (rand () >> 4 ) & 3 ;
26+ if (v == 0 && !edges.empty ()) { // remove
27+ int r = (rand () >> 4 ) % sz (edges);
28+ pii ed = edges[r];
29+ swap (edges[r], edges.back ());
30+ edges.pop_back ();
31+ if (rand () & 16 )
32+ lc.cut (ed.first , ed.second );
33+ else
34+ lc.cut (ed.second , ed.first );
35+ } else {
36+ int a = (rand () >> 4 ) % N;
37+ int b = (rand () >> 4 ) % N;
38+ uf.e .assign (N, -1 );
39+ trav (ed, edges) uf.join (ed.first , ed.second );
40+ bool c = uf.same_set (a, b);
41+ if (!c && v != 1 ) {
42+ lc.link (a, b);
43+ edges.emplace_back (a, b);
3744 } else {
38- int a = (rand () >> 4 ) % N;
39- int b = (rand () >> 4 ) % N;
40- uf.e .assign (N, -1 );
41- trav (ed, edges) uf.join (ed.first , ed.second );
42- bool c = uf.same_set (a, b);
43- if (!c && v != 1 ) {
44- lc.link (a, b);
45- edges.emplace_back (a, b);
46- } else {
47- assert (lc.connected (a, b) == c);
48- }
45+ assert (lc.connected (a, b) == c);
4946 }
5047 }
5148 }
52- clog << ' .' ;
5349 }
50+ cout<<" Tests passed!" <<endl;
5451}
0 commit comments