結果
問題 | No.1711 Divide LCM |
ユーザー | mtsd |
提出日時 | 2021-10-15 23:14:26 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 208 ms / 4,000 ms |
コード長 | 24,269 bytes |
コンパイル時間 | 2,584 ms |
コンパイル使用メモリ | 205,016 KB |
実行使用メモリ | 44,364 KB |
最終ジャッジ日時 | 2024-09-17 18:12:54 |
合計ジャッジ時間 | 10,275 ms |
ジャッジサーバーID (参考情報) |
judge6 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 3 ms
6,944 KB |
testcase_04 | AC | 6 ms
6,940 KB |
testcase_05 | AC | 18 ms
6,940 KB |
testcase_06 | AC | 7 ms
6,944 KB |
testcase_07 | AC | 16 ms
6,944 KB |
testcase_08 | AC | 9 ms
6,940 KB |
testcase_09 | AC | 32 ms
6,940 KB |
testcase_10 | AC | 7 ms
6,940 KB |
testcase_11 | AC | 42 ms
6,940 KB |
testcase_12 | AC | 8 ms
6,940 KB |
testcase_13 | AC | 2 ms
6,940 KB |
testcase_14 | AC | 4 ms
6,940 KB |
testcase_15 | AC | 5 ms
6,944 KB |
testcase_16 | AC | 2 ms
6,944 KB |
testcase_17 | AC | 4 ms
6,944 KB |
testcase_18 | AC | 101 ms
8,552 KB |
testcase_19 | AC | 100 ms
8,552 KB |
testcase_20 | AC | 102 ms
8,564 KB |
testcase_21 | AC | 154 ms
19,160 KB |
testcase_22 | AC | 208 ms
44,364 KB |
testcase_23 | AC | 195 ms
44,188 KB |
testcase_24 | AC | 112 ms
11,668 KB |
testcase_25 | AC | 108 ms
11,676 KB |
testcase_26 | AC | 111 ms
11,792 KB |
testcase_27 | AC | 111 ms
12,272 KB |
testcase_28 | AC | 116 ms
11,864 KB |
testcase_29 | AC | 3 ms
6,944 KB |
testcase_30 | AC | 130 ms
14,400 KB |
testcase_31 | AC | 3 ms
6,944 KB |
testcase_32 | AC | 154 ms
19,000 KB |
testcase_33 | AC | 156 ms
19,192 KB |
testcase_34 | AC | 7 ms
6,944 KB |
testcase_35 | AC | 119 ms
10,940 KB |
testcase_36 | AC | 121 ms
13,772 KB |
testcase_37 | AC | 110 ms
13,792 KB |
testcase_38 | AC | 97 ms
13,564 KB |
testcase_39 | AC | 140 ms
19,500 KB |
testcase_40 | AC | 4 ms
6,944 KB |
testcase_41 | AC | 3 ms
6,944 KB |
testcase_42 | AC | 4 ms
6,944 KB |
testcase_43 | AC | 4 ms
6,944 KB |
testcase_44 | AC | 4 ms
6,940 KB |
コンパイルメッセージ
main.cpp: In function 'int main()': main.cpp:511:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions] 511 | for(auto [x,c]:mx){ | ^ main.cpp: In lambda function: main.cpp:535:26: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions] 535 | for(auto [p,e]:a[i]){ | ^ main.cpp: In function 'int main()': main.cpp:575:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions] 575 | for(auto [p,e]:a[i]){ | ^
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define inf 1000000007 #define MP make_pair #define MT make_tuple #define PB push_back #define fi first #define se second #define rep(i,n) for(int i = 0; i < (int)(n); ++i) #define rrep(i,n) for(int i = (int)n-1; i >= 0; --i) #define srep(i,a,b) for(int i = (int)a; i < (int)(b); ++i) #define all(x) (x).begin(),(x).end() #define SUM(v) accumulate(all(v), 0LL) #define MIN(v) *min_element(all(v)) #define MAX(v) *max_element(all(v)) #define lb(c, x) distance((c).begin(), lower_bound(all(c), (x))) #define ub(c, x) distance((c).begin(), upper_bound(all(c), (x))) #define UNIQUE(x) sort(all(x)), x.erase(unique(all(x)), x.end()) #define SZ(c) (int)(c).size() template<typename T> ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<(int)vec.size(); i++) { os << vec[i] << (i + 1 == (int)vec.size() ? "" : ", "); } os << "}"; return os; } // pair出力 template<typename T, typename U> ostream& operator << (ostream& os, pair<T, U> pair_var) { os << "(" << pair_var.first << ", " << pair_var.second << ")"; return os; } // map出力 template<typename T, typename U> ostream& operator << (ostream& os, map<T, U>& map_var) { os << "{"; for(auto itr = map_var.begin(); itr != map_var.end(); itr++){ os << "(" << itr->first << ", " << itr->second << ")"; itr++; if(itr != map_var.end()) os << ", "; itr--; } os << "}"; return os; } // set 出力 template<typename T> ostream& operator << (ostream& os, set<T>& set_var) { os << "{"; for(auto itr = set_var.begin(); itr != set_var.end(); itr++){ os << (*itr); ++itr; if(itr != set_var.end()) os << ", "; itr--; } os << "}"; return os; } #define overload2(_1, _2, name, ...) name #define vec(type, name, ...) vector<type> name(__VA_ARGS__) #define VEC(type, name, size) \ vector<type> name(size); \ IN(name) #define vv(type, name, h, ...) vector<vector<type>> name(h, vector<type>(__VA_ARGS__)) #define VV(type, name, h, w) \ vector<vector<type>> name(h, vector<type>(w)); \ IN(name) #define vvv(type, name, h, w, ...) vector<vector<vector<type>>> name(h, vector<vector<type>>(w, vector<type>(__VA_ARGS__))) #define vvvv(type, name, a, b, c, ...) \ vector<vector<vector<vector<type>>>> name(a, vector<vector<vector<type>>>(b, vector<vector<type>>(c, vector<type>(__VA_ARGS__)))) #define INT(...) \ int __VA_ARGS__; \ IN(__VA_ARGS__) #define LL(...) \ ll __VA_ARGS__; \ IN(__VA_ARGS__) #define STR(...) \ string __VA_ARGS__; \ IN(__VA_ARGS__) #define CHR(...) \ char __VA_ARGS__; \ IN(__VA_ARGS__) #define DBL(...) \ double __VA_ARGS__; \ IN(__VA_ARGS__) int scan() { return getchar(); } void scan(int &a) { cin >> a; } void scan(long long &a) { cin >> a; } void scan(char &a) { cin >> a; } void scan(double &a) { cin >> a; } void scan(string &a) { cin >> a; } template <class T, class S> void scan(pair<T, S> &p) { scan(p.first), scan(p.second); } template <class T> void scan(vector<T> &); template <class T> void scan(vector<T> &a) { for(auto &i : a) scan(i); } template <class T> void scan(T &a) { cin >> a; } void IN() {} template <class Head, class... Tail> void IN(Head &head, Tail &...tail) { scan(head); IN(tail...); } const string YESNO[2] = {"NO", "YES"}; const string YesNo[2] = {"No", "Yes"}; const string yesno[2] = {"no", "yes"}; void YES(bool t = 1) { cout << YESNO[t] << endl; } void NO(bool t = 1) { YES(!t); } void Yes(bool t = 1) { cout << YesNo[t] << endl; } void No(bool t = 1) { Yes(!t); } void yes(bool t = 1) { cout << yesno[t] << endl; } void no(bool t = 1) { yes(!t); } #ifdef LOCAL void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...); } #define dbg(...) \ cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl #else #define dbg(...) (void(0)) #define dump(x) (void(0)) #endif template<typename A, typename T> std::enable_if_t<std::is_convertible<T, A>::value> fill(A& array, const T& val) { array = val; } template<typename A, typename T> std::enable_if_t<!std::is_convertible<T, A>::value> fill(A& array, const T& val) { for (auto& a : array) { fill(a, val); } } template <class T> T ceil(T x, T y) {assert(y >= 1);return (x > 0 ? (x + y - 1) / y : x / y);} template <class T> T floor(T x, T y) {assert(y >= 1);return (x > 0 ? x / y : (x + y - 1) / y);} vector<int> iota(int n) {vector<int> a(n);iota(all(a), 0);return a;} template <class T> T POW(T x, int n) {T res = 1;for(; n; n >>= 1, x *= x){if(n & 1) res *= x;}return res;} ll pow2(int i) { return 1LL << i; } int topbit(signed t) { return t == 0 ? -1 : 31 - __builtin_clz(t); } int topbit(ll t) { return t == 0 ? -1 : 63 - __builtin_clzll(t); } int lowbit(signed a) { return a == 0 ? 32 : __builtin_ctz(a); } int lowbit(ll a) { return a == 0 ? 64 : __builtin_ctzll(a); } // int allbit(int n) { return (1 << n) - 1; } ll allbit(ll n) { return (1LL << n) - 1; } int popcount(signed t) { return __builtin_popcount(t); } int popcount(ll t) { return __builtin_popcountll(t); } bool ispow2(int i) { return i && (i & -i) == i; } template <class S> void fold_in(vector<S> &v) {} template <typename Head, typename... Tail, class S> void fold_in(vector<S> &v, Head &&a, Tail &&...tail) { for(auto e : a) v.emplace_back(e); fold_in(v, tail...); } template <class S> void renumber(vector<S> &v) {} template <typename Head, typename... Tail, class S> void renumber(vector<S> &v, Head &&a, Tail &&...tail) { for(auto &&e : a) e = lb(v, e); renumber(v, tail...); } template <class S, class... Args> void zip(vector<S> &head, Args &&...args) { vector<S> v; fold_in(v, head, args...); sort(all(v)), v.erase(unique(all(v)), v.end()); renumber(v, head, args...); } template<class T> inline bool chmax(T &a, T b){ if(a<b){ a = b; return true; } return false; } template<class T> inline bool chmin(T &a, T b){ if(a>b){ a = b; return true; } return false; } template<class _Key, class _Tp, class _Hash, bool DOWNSIZE> class UnorderedMapIterator; template<class _Key, class _Tp, class _Hash = hash<_Key>, bool DOWNSIZE = false> class UnorderedMap { private: using iterator = UnorderedMapIterator<_Key, _Tp, _Hash, DOWNSIZE>; using value_type = _Tp; using data_type = pair<_Key, _Tp>; using aligned_pointer = typename aligned_storage<sizeof(value_type), alignof(value_type)>::type; friend UnorderedMapIterator<_Key, _Tp, _Hash, DOWNSIZE>; struct bucket { _Key _key; short int _dist; bool _last, _end; aligned_pointer _value_ptr; bucket() noexcept : _dist(-1), _last(false), _end(false){} bucket& operator=(const bucket& another) noexcept { _key = another._key, _dist = another._dist, _last = another._last, _end = another._end; if(!another.empty()){ new(&_value_ptr) value_type(*reinterpret_cast<const value_type*>(&another._value_ptr)); } return *this; } ~bucket(){ if(!empty()) _delete(); } inline void clear() noexcept { _dist = -1; } inline void _delete(){ _dist = -1, value_ptr()->~value_type(); } inline bool empty() const noexcept { return (_dist == -1); } inline value_type& value() noexcept { return *reinterpret_cast<value_type*>(&_value_ptr); } inline value_type* value_ptr() noexcept { return reinterpret_cast<value_type*>(&_value_ptr); } inline void new_value(value_type&& value){ new(&_value_ptr) value_type(move(value)); } }; inline static unsigned int ceilpow2(unsigned int u) noexcept { if(u == 0u) return 0u; --u, u |= u >> 1, u |= u >> 2, u |= u >> 4, u |= u >> 8; return (u | (u >> 16)) + 1u; } inline static bucket *increment(bucket *cur) noexcept { for(++cur; !cur->_end; ++cur){ if(!cur->empty()) break; } return cur; } inline bucket *next_bucket(bucket *cur) const noexcept { return cur->_last ? _buckets : cur + 1; } inline unsigned int make_hash(const _Key& key) const noexcept { return _Hash()(key); } inline float load_rate() const noexcept { return (float)_data_count / _bucket_count; } bucket *insert(bucket *cur, _Key&& key, short int dist, value_type&& value){ bucket *ret = cur; bool flag = false; while(true){ if(cur->empty()){ cur->_key = move(key), cur->_dist = dist, cur->new_value(move(value)); if(!flag) ret = cur, flag = true; break; }else if(dist > cur->_dist){ swap(key, cur->_key), swap(dist, cur->_dist), swap(value, cur->value()); if(!flag) ret = cur, flag = true; } ++dist; cur = next_bucket(cur); } return ret; } template<class Key> bucket *_find(Key&& key, bool push = false){ unsigned int hash = make_hash(key); bucket *cur = _buckets + (hash & _mask); short int dist = 0; while(dist <= cur->_dist){ if(key == cur->_key) return cur; ++dist, cur = next_bucket(cur); } if(!push) return _buckets + _bucket_count; ++_data_count; if(rehash_check()){ cur = _buckets + (hash & _mask), dist = 0; } value_type new_value = value_type(); _Key new_key = forward<Key>(key); return insert(cur, move(new_key), dist, move(new_value)); } template<class Data> bucket *find_insert(Data&& data){ const _Key& key = data.first; unsigned int hash = make_hash(key); bucket *cur = _buckets + (hash & _mask); short int dist = 0; while(dist <= cur->_dist){ if(key == cur->_key) return cur; ++dist, cur = next_bucket(cur); } ++_data_count; if(rehash_check()){ cur = _buckets + (hash & _mask), dist = 0; } data_type new_data = forward<Data>(data); return insert(cur, move(new_data.first), dist, move(new_data.second)); } template<typename... Args> bucket *emplace(Args&&... args){ return find_insert(data_type(forward<Args>(args)...)); } bucket *backward_shift(bucket *cur, bool next_ret){ bucket *next = next_bucket(cur), *ret = cur; if(next->_dist < 1) return next_ret ? increment(cur) : cur; do { cur->_key = next->_key, cur->_dist = next->_dist - 1; cur->new_value(move(next->value())); cur = next, next = next_bucket(cur); }while(next->_dist >= 1); cur->clear(); return ret; } bucket *erase_impl(bucket *cur, bool next_ret){ assert(static_cast<size_t>(cur - _buckets) != _bucket_count); cur->_delete(); --_data_count; return backward_shift(cur, next_ret); } bucket *erase_itr(bucket *cur, bool next_ret = true){ const _Key key = cur->_key; return erase_impl(rehash_check() ? _find(key) : cur, next_ret); } size_t erase_key(const _Key& key){ rehash_check(); bucket *cur = _find(key); if(static_cast<size_t>(cur - _buckets) == _bucket_count){ return 0; }else{ erase_impl(_find(key), false); return 1; } } bool rehash_check(){ if(_bucket_count == 0){ rehash(1u); return true; }else if(load_rate() >= MAX_LOAD_RATE){ rehash(_bucket_count * 2u); return true; }else if(DOWNSIZE){ if(load_rate() <= MIN_LOAD_RATE && _bucket_count >= DOWNSIZE_THRESHOLD){ rehash(_bucket_count / 2u); return true; } } return false; } void move_data(bucket *cur){ insert(_buckets + (make_hash(cur->_key) & _mask), move(cur->_key), 0, move(cur->value())); } void rehash(unsigned int new_bucket_count){ UnorderedMap new_unordered_map(new_bucket_count); new_unordered_map._data_count = _data_count; for(bucket *cur = _buckets; !cur->_end; ++cur){ if(!cur->empty()){ new_unordered_map.move_data(cur); } } swap(*this, new_unordered_map); } friend void swap(UnorderedMap& ump1, UnorderedMap& ump2){ swap(ump1._bucket_count, ump2._bucket_count); swap(ump1._mask, ump2._mask); swap(ump1._data_count, ump2._data_count); swap(ump1._buckets, ump2._buckets); } private: unsigned int _bucket_count, _mask, _data_count; bucket *_buckets; public: const float MAX_LOAD_RATE = 0.5f; const float MIN_LOAD_RATE = 0.1f; const unsigned int DOWNSIZE_THRESHOLD = 16u; UnorderedMap(unsigned int bucket_size = 0u) : _bucket_count(ceilpow2(bucket_size)), _mask(_bucket_count - 1), _data_count(0u), _buckets(new bucket[_bucket_count + 1]){ if(_bucket_count > 0) _buckets[_bucket_count - 1]._last = true; else _mask = 0; _buckets[_bucket_count]._end = true; } UnorderedMap(const UnorderedMap& another) : _bucket_count(another._bucket_count), _mask(another._mask), _data_count(another._data_count){ _buckets = new bucket[_bucket_count + 1u]; for(unsigned int i = 0u; i <= _bucket_count; ++i){ _buckets[i] = another._buckets[i]; } } UnorderedMap(UnorderedMap&& another) : _bucket_count(move(another._bucket_count)), _mask(move(another._mask)), _data_count(move(another._data_count)), _buckets(another._buckets){ another._buckets = nullptr; } UnorderedMap& operator=(const UnorderedMap& another){ delete[] _buckets; _bucket_count = another._bucket_count; _mask = another._mask; _data_count = another._data_count; _buckets = new bucket[_bucket_count + 1u]; for(unsigned int i = 0u; i <= _bucket_count; ++i){ _buckets[i] = another._buckets[i]; } return *this; } UnorderedMap& operator=(UnorderedMap&& another){ delete[] _buckets; _bucket_count = move(another._bucket_count); _mask = move(another._mask); _data_count = move(another._data_count); _buckets = another._buckets; another._buckets = nullptr; return *this; } void allocate(unsigned int element_size){ rehash(ceilpow2(ceil(element_size / MAX_LOAD_RATE) + 1)); } ~UnorderedMap(){ delete[] _buckets; } friend ostream& operator<< (ostream& os, UnorderedMap& ump) noexcept { for(auto val : ump) os << '{' << val.first << ',' << val.second << "} "; return os; } _Tp& operator[](const _Key& key){ return _find(key, true)->value(); } _Tp& operator[](_Key&& key){ return _find(move(key), true)->value(); } const _Tp& at(const _Key& key){ bucket *res = _find(key); if(res == _buckets + _bucket_count) __throw_out_of_range("Unordered_Map::at"); return res->value(); } void clear(){ UnorderedMap new_unordered_map(0u); swap(*this, new_unordered_map); } size_t size() const noexcept { return _data_count; } size_t bucket_count() const noexcept { return _bucket_count; } bool empty() const noexcept { return (_data_count == 0); } iterator begin() noexcept { return (_buckets->empty() && _bucket_count > 0) ? iterator(increment(_buckets)) : iterator(_buckets); } iterator end() noexcept { return iterator(_buckets + _bucket_count); } iterator find(const _Key& key){ return iterator(_find(key)); } iterator insert(const data_type& data){ return iterator(find_insert(data)); } iterator insert(data_type&& data){ return iterator(find_insert(move(data))); } template<typename... Args> iterator emplace(Args&&... args){ return iterator(_emplace(forward<Args>(args)...)); } size_t erase(const _Key& key){ return erase_key(key); } iterator erase(const iterator& itr){ return iterator(erase_itr(itr.bucket_ptr)); } void simple_erase(const _Key& key){ erase_key(key); } void simple_erase(const iterator& itr){ erase_itr(itr.bucket_ptr, false); } // DEBUG 用 short int maximum_distance() const noexcept { short int ret = -1; for(bucket *cur = _buckets; !cur->_end; ++cur){ ret = max(ret, cur->_dist); } return ret; } }; template<class _Key, class _Tp, class _Hash, bool DOWNSIZE> class UnorderedMapIterator { private: friend UnorderedMap<_Key, _Tp, _Hash, DOWNSIZE>; typename UnorderedMap<_Key, _Tp, _Hash, DOWNSIZE>::bucket *bucket_ptr; using iterator_category = forward_iterator_tag; using value_type = pair<const _Key, _Tp>; using difference_type = ptrdiff_t; using reference = pair<const _Key&, _Tp&>; private: UnorderedMapIterator(typename UnorderedMap<_Key, _Tp, _Hash, DOWNSIZE>::bucket *_bucket_ptr) noexcept : bucket_ptr(_bucket_ptr){} public: UnorderedMapIterator() noexcept : bucket_ptr(){} UnorderedMapIterator(const UnorderedMapIterator& itr) noexcept : bucket_ptr(itr.bucket_ptr){} UnorderedMapIterator& operator=(const UnorderedMapIterator& itr) & noexcept { return bucket_ptr = itr.bucket_ptr, *this; } UnorderedMapIterator& operator=(const UnorderedMapIterator&& itr) & noexcept { return bucket_ptr = itr.bucket_ptr, *this; } reference operator*() const noexcept { return {bucket_ptr->_key, bucket_ptr->value()}; } UnorderedMapIterator& operator++() noexcept { return bucket_ptr = UnorderedMap<_Key, _Tp, _Hash, DOWNSIZE>::increment(bucket_ptr), *this; } UnorderedMapIterator operator++(int) const noexcept { return UnorderedMapIterator(UnorderedMap<_Key, _Tp, _Hash, DOWNSIZE>::increment(this->bucket_ptr)); } bool operator==(const UnorderedMapIterator& itr) const noexcept { return !(*this != itr); }; bool operator!=(const UnorderedMapIterator& itr) const noexcept { return bucket_ptr != itr.bucket_ptr; } }; int main(){ INT(n); vector<vector<pair<int,int> > > a; vector<int> num(n,1); UnorderedMap<int,int> mx; rep(i,n){ INT(m); vector<pair<int,int> > q; rep(j,m){ INT(p,e); chmax(mx[p],e); q.push_back({p,e}); rep(zz,e)num[i] *= p; } a.push_back(q); } vector<int> pr; for(auto [x,c]:mx){ pr.push_back(x); } reverse(all(pr)); ll K = 1; ll cc = 0; vector<int> ans; for(auto x:pr){ cc++; K *=x; ans.push_back(x); if(K>=1000000000){ break; } } auto answer = [&]()->vector<vector<int> >{ vector<vector<int> > r; vector<char> flag(n); dbg(ans); rep(z,ans.size()){ vector<int> ttt; rep(i,n){ bool fff = 1; if(flag[i])continue; for(auto [p,e]:a[i]){ if(ans[z]==p){ if(mx[p]==e)fff = 0; } } if(fff){ ttt.push_back(i); flag[i] = 1; } } r.push_back(ttt); } rep(i,n){ if(!flag[i]){ return vector<vector<int>>(); } } return r; }; if(cc==2){ vector<vector<int> > res = answer(); if(res.size()==0){ cout << -1 << endl; return 0; } cout << res.size() << "\n"; for(auto&v:res){ cout << v.size() << " "; for(auto x:v){ cout << num[x] << " "; } cout << "\n"; } return 0; } UnorderedMap<int,int> mp; vector<vector<int> > s(n); rep(i,n){ vector<int> t; for(auto [p,e]:a[i]){ if(mx[p]==e){ t.push_back(p); } } if(t.size()==mx.size()){ cout << -1 << endl; return 0; } s[i] = t; int N = t.size(); vector<int>pp(1<<N); pp[0] = 1; rep(bits,1<<N){ if(bits==0)continue; int bb = topbit(bits); pp[bits] = pp[bits^(1<<bb)] * t[bb]; mp[pp[bits]]++; } } dbg(num); dbg(mp); srep(c,2,cc){ bool ok = 0; vector<int> tmp; auto dfs = [&](auto&&f,int X,int s,int id)->void{ if(s==c){ if(mp[X]==0){ ok = 1; ans = tmp; } return; } if(id==pr.size())return; int p = pr[id]; tmp.push_back(p); f(f,X*p,s+1,id+1); if(ok)return; tmp.pop_back(); f(f,X,s,id+1); }; dfs(dfs,1,0,0); if(ok){ vector<vector<int> > res = answer(); if(res.size()==0){ cerr<< "error" << endl; cout << -1 << endl; return 0; } cout << res.size() << "\n"; for(auto&v:res){ cout << v.size() << " "; for(auto x:v){ cout << num[x] << " "; } cout << "\n"; } return 0; } } vector<vector<int> > res = answer(); if(res.size()==0){ cout << -1 << endl; return 0; } cout << res.size() << "\n"; for(auto&v:res){ cout << v.size() << " "; for(auto x:v){ cout << num[x] << " "; } cout << "\n"; } return 0; }