Untitled
unknown
c_cpp
a year ago
1.7 kB
3
Indexable
#include "bits/stdc++.h" using namespace std; #ifdef LOCAL #include "debug.h" #else #define debug(x...) #endif struct custom_hash { size_t operator()(vector<int32_t> const& vec) const { size_t seed = vec.size(); for(auto& i : vec) { seed ^= i + 0x9e3779b9 + (seed << 6) + (seed >> 2); } return seed; } }; void solve() { int n; cin >> n; vector<pair<int, int>> p(n); for (int i = 0; i < n; i++) { cin >> p[i].first >> p[i].second; } unordered_set<vector<int>, custom_hash> s; for (int i = 0; i < (1 << n); i++) { unordered_set<int> f; bool add = true; vector<int> value(n), cur(n); iota(cur.begin(), cur.end(), 0); for (int j = 0; j < n; j++) { if ((i >> j) & 1) { if (f.contains(p[j].first)) { add = false; break; } f.insert(p[j].first); value[j] = p[j].first; } else { if (f.contains(p[j].second)) { add = false; break; } f.insert(p[j].second); value[j] = p[j].second; } } if (!add) { continue; } sort(cur.begin(), cur.end(), [&](int lhs, int rhs) { return value[lhs] < value[rhs]; }); s.insert(cur); } cout << s.size(); } signed main() { ios::sync_with_stdio(false); cin.tie(NULL); int tests = 1; // cin >> tests; while (tests--) { solve(); } return 0; }
Editor is loading...