#include #include #include #include #include #include using namespace std; typedef set SI; typedef long long LL; const int MAXT = 50; const int MAXN = 100; const int MAXM = 200; const LL MAXC = 10000; struct bundle { SI b; LL c; }; typedef vector VB; int cases; //either a and b are disjoint, or one is contained in the other (can be equal) bool ok(const SI& a, const SI& b) { if (a.size() > b.size()) return ok(b, a); auto ai = a.begin(), bi = b.begin(); int cnt = 0; while (ai != a.end() && bi != b.end()) { if (*ai < *bi) ++ai; else if (*ai > *bi) ++bi; else { ++cnt; ++ai; ++bi; } } return cnt == 0 || cnt == a.size(); } //the items are already numbered from 1 to n void dump(const VB& v, int n) { assert(cases > 0); assert(1 <= n && n <= MAXN); assert(1 <= v.size() && v.size() <= MAXM); vector f(n, false); cout << n << ' ' << v.size() << endl; for (int i = 0; i < v.size(); ++i) { assert(1 <= v[i].c && v[i].c <= MAXC); //can actually check for laminarity in linear time, //will do if we use larger data for (int j = 0; j < i; ++j) assert(ok(v[i].b, v[j].b)); cout << v[i].c << ' ' << v[i].b.size(); for (auto x : v[i].b) { cout << ' ' << x; f[x-1] = true; } cout << endl; } for (auto x : f) assert(x); --cases; } void jumble(VB& v, int n) { vector p(v.size()), nx(n); for (int i = 0; i < v.size(); ++i) p[i] = i; for (int i = 0; i < n; ++i) nx[i] = i+1; for (int i = v.size()-1; i > 0; --i) swap(p[i], p[rand()%(i+1)]); for (int i = n-1; i > 0; --i) swap(nx[i], nx[rand()%(i+1)]); VB tmp(v.size()); for (int i = 0; i < v.size(); ++i) { tmp[i].c = v[p[i]].c; for (auto x : v[p[i]].b) tmp[i].b.insert(nx[x-1]); } v = tmp; } bundle init_b(int n, int c) { bundle b; for (int i = 1; i <= n; ++i) b.b.insert(i); b.c = c; return b; } void one(int n) { VB v(1, init_b(n, 1)); dump(v, n); } //dumps 3 void two_copy(int n) { VB v(2, init_b(n, 1)); dump(v, n); v[1].c = 2; dump(v, n); swap(v[0], v[1]); dump(v, n); } void singletons(int n) { VB v(n); for (int i = 0; i < n; ++i) { v[i].c = 1+rand()%5; v[i].b.insert(i+1); } jumble(v, n); dump(v, n); } void big_small(int n, int lo, int hi) { VB v(n); for (int i = 0; i < n; ++i) { v[i].c = lo; v[i].b.insert(i+1); } jumble(v, n); v.push_back(init_b(n, hi)); dump(v, n); swap(v[n], v[0]); dump(v, n); swap(v[0], v[n/2]); dump(v, n); } bundle merge(const bundle& a, const bundle& b) { bundle c = a; for (auto x : b.b) c.b.insert(x); c.c += b.c; return c; } void laminar(int k) { int n = (1<