#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include #include #include #include using namespace std; typedef long long ll; unordered_map pri; int a[100010][10],b[100010][10],A[100010],sz[100010]; vector c[100010],pp; unordered_map hs; unordered_map se,zob; ll inf = 1000000000000000; bool ok = false; vector ans; bool used[100010]; void solve(int pos,int target_num,vector now,ll val){ if(ok) return; if(now.size()==target_num){ // cout << "result = :"; // for(int x:now) cout << x << " "; // cout << "\n"; // cout << "value = " << val << "\n"; if(zob.find(val)==zob.end()){ ok = true; ans = now; } return; } if(now.size() + pp.size() - pos==target_num){ val ^= hs[pp[pos]]; now.push_back(pp[pos]); solve(pos + 1,target_num,now,val); }else{ for(int i=pos;i<(int)pp.size() + (int)now.size() - target_num + 1;i++){ val ^= hs[pp[i]]; now.push_back(pp[i]); solve(i + 1,target_num,now,val); val ^= hs[pp[i]]; now.pop_back(); } } } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int i,j,n; cin >> n; for(i=0;i> sz[i]; A[i] = 1; for(j=0;j> a[i][j] >> b[i][j]; pri[a[i][j]] = max(pri[a[i][j]],b[i][j]); for(int k=0;k dist(0, inf); for(auto x:pri) hs[x.first] = dist(engine); int mx = -1; for(i=0;i>k&1) val2 ^= hs[c[i][k]]; } zob[val2] = true; } } if(mx==pri.size()){ cout << -1 << "\n"; return 0; } for(auto x:pri) pp.push_back(x.first); std::random_device seed_gen2; std::default_random_engine engine2(seed_gen2()); shuffle(pp.begin(),pp.end(),engine2); for(i=1;i<=10;i++){ vector now; if(!ok) solve(0,i,now,0); } cout << ans.size() << "\n"; for(i=0;i vec; for(i=0;i