Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- void doRoutine() {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- srand(322179);
- #ifdef LOCAL
- freopen("input.txt", "rt", stdin);
- freopen("output.txt", "wt", stdout);
- #endif
- }
- #define DBG(VAR) cerr << #VAR << ": " << VAR << endl
- #define all(x) x.begin(), x.end()
- #define vb vector<bool>
- #define vi vector<int>
- #define vvi vector<vi>
- #define pii pair<int, int>
- #define fi first
- #define se second
- #define pb push_back
- #define vc vector
- #define $ make_pair
- #ifndef LOCAL
- #define cerr if(0) cerr
- #define DBG(...) (true)
- #endif
- #define D double
- //#define int long long
- typedef long long ll;
- // ----------------------------- CODE NOW ------------------------
- template <typename T1, typename T2>
- istream & operator >> (istream & in, pair <T1, T2> & p) {
- in >> p.fi >> p.se;
- return in;
- }
- template <typename T1, typename T2>
- ostream & operator << (ostream & out, pair <T1, T2> p) {
- out << "{" << p.fi << ", " << p.se << "}";
- return out;
- }
- template <typename T>
- ostream & operator << (ostream & out, vector <T> arr) {
- for (int i = 0; i < arr.size(); ++i)
- out << arr[i] << " ";
- out << endl;
- return out;
- }
- template <typename T>
- istream & operator >> (istream & in, vector <T> & arr) {
- for (int i = 0; i < arr.size(); ++i)
- in >> arr[i];
- return in;
- }
- vector <vector <int> > g;
- vector <int> color;
- void dfs(int v, int clr) {
- color[v] = clr;
- for (int i = 0; i < g[v].size(); ++i) {
- int to = g[v][i];
- if (color[to] == 0)
- dfs(to, (clr % 2 ? clr + 1 : clr - 1));
- }
- }
- signed main() {
- doRoutine();
- int n;
- cin >> n;
- g.resize(n);
- vector <string> plc(n);
- vector <vector <int> > arr(n);
- for (int i = 0; i < n; ++i) {
- string s;
- cin >> s;
- plc[i] = s;
- int sz;
- cin >> sz;
- arr[i].resize(sz);
- cin >> arr[i];
- for (int j = 0; j < arr[i].size(); ++j)
- arr[i][j]--;
- }
- for (int i = 0; i < n; ++i) {
- for (auto x : arr[i]) {
- if (plc[x] != plc[i]) {
- g[x].push_back(i);
- g[i].push_back(x);
- }
- }
- }
- set <int> bb;
- for (int i = 0; i < n; ++i) {
- set <int> ss;
- for (auto x : arr[i])
- ss.insert(x);
- for (int j = 0; j < n; ++j) {
- if (plc[j] == plc[i])
- continue;
- for (auto x : arr[j])
- {
- if (plc[x] != plc[j] && plc[x] != plc[i] && ss.count(x)) {
- bb.insert(i);
- bb.insert(j);
- }
- }
- }
- }
- for (auto x : bb)
- cerr << x << endl;
- vector <int> ansall(10000);
- for (int i = 0; i < n; ++i) {
- color.assign(n, 0);
- set <int> ban = bb;
- vector <int> ans;
- if (plc[i] == "pool") {
- ban.insert(i);
- for (int j = 0; j < n; ++j) {
- for (auto x : arr[j]) {
- if (x == i && plc[j] != "pool") {
- ans.resize(10000);
- }
- }
- }
- }
- else {
- ban.insert(i);
- for (int j = 0; j < n; ++j) {
- for (auto x : arr[j]) {
- if (x == i && plc[j] != "pool") {
- if (plc[j] != plc[i])
- arr.resize(10001);
- else
- ban.insert(j);
- }
- }
- }
- }
- int cl = 1;
- for (int i = 0; i < n; ++i) {
- if (color[i] == 0) {
- dfs(i, cl);
- set <int> a, b;
- bool flag1 = false, flag2 = false;
- for (int i = 0; i < n; ++i) {
- if (color[i] == cl) {
- a.insert(i);
- if (ban.count(i))
- flag1 = true;
- }
- else if (color[i] == cl + 1) {
- b.insert(i);
- if (ban.count(i))
- flag2 = true;
- }
- }
- if (a.size() > b.size()) {
- swap(a, b);
- swap(flag1, flag2);
- }
- if (flag1 && flag2) {
- ans.resize(10001);
- break;
- }
- else if (flag2) {
- for (auto x : b)
- ans.push_back(x);
- }
- else {
- for (auto x : a)
- ans.push_back(x);
- }
- cl += 2;
- }
- }
- if (ans.size() < ansall.size())
- ansall = ans;
- }
- assert(ansall.size() <= n);
- cout << ansall.size() << endl;
- for (auto & x : ansall)
- x++;
- cout << ansall << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement