Submission #1035420

# Submission time Handle Problem Language Result Execution time Memory
1035420 2024-07-26T10:52:53 Z vjudge1 Political Development (BOI17_politicaldevelopment) C++17
0 / 100
3000 ms 357456 KB
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;

#define all(x) x.begin(), x.end()

const int N = 5e4, X = 5e4, X2 = 5e3;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n, k, c, ans;
vector<int> vt, adj[N];
bitset<N> bt[N], bt2[N], taken, toTake;

void dfs2(int x) {
  if (c++ > X) return;

  int sz = taken.count();
  ans = max(ans, sz);
  
  shuffle(all(adj[x]), rng);
  for (int& y : adj[x]) {
    if (!taken[y] && (taken & bt2[y]).count() < sz) continue;

    taken[y] = 1;
    bitset<N> toTakePrev = toTake;
    toTake &= bt2[y];
    dfs2(y);
    toTake = toTakePrev;
    taken[y] = 0;

    if (c > X2) return;
  }
}

void dfs(int x) {
  //cerr << c << " " << x << endl;
  if (c++ > X) return;
//cerr << c << " " << x << endl;
  int sz = taken.count();
  ans = max(ans, sz);
//cerr << c << " " << x << endl;
  shuffle(all(adj[x]), rng);
  for (int& y : adj[x]) {
    if (!taken[y] && (taken & bt2[y]).count() < sz) continue;
//cerr << c << " " << x << endl;
    taken[y] = 1;
    bitset<N> toTakePrev = toTake;
    toTake &= bt2[y];
    dfs(y);
    toTake = toTakePrev;
    taken[y] = 0;
//cerr << c << " " << x << endl;
    if (c > X) return;
  }
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);

  cin >> n >> k;
  c = 0;
  ans = 1;
  vt.resize(n);
  for (int i = 0; i < n; i++) {
    vt[i] = i;
    bt2[i][i] = toTake[i] = 1;

    int x; cin >> x;
    for (int j = 0; j < x; j++) {
      int y; cin >> y;
      bt[i][y] = 1;

      if (bt[y][i]) {
        bt2[i][y] = 1;
        adj[i].push_back(y);

        bt2[y][i] = 1;
        adj[y].push_back(i);
      }
    }
  }
  shuffle(all(vt), rng);

  for (int i = 0; i < n && c < X; i++) {
    dfs(vt[i]);
  }

  for (int i = 0; i < n; i++) {
    c = 0;
    taken.reset();
    toTake.reset();
    toTake = ~toTake;
    dfs2(vt[i]);
  }

  cout << ans << "\n";
}

Compilation message

politicaldevelopment.cpp: In function 'void dfs2(int)':
politicaldevelopment.cpp:23:47: warning: comparison of integer expressions of different signedness: 'std::size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   23 |     if (!taken[y] && (taken & bt2[y]).count() < sz) continue;
      |                      ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
politicaldevelopment.cpp: In function 'void dfs(int)':
politicaldevelopment.cpp:45:47: warning: comparison of integer expressions of different signedness: 'std::size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   45 |     if (!taken[y] && (taken & bt2[y]).count() < sz) continue;
      |                      ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 2195 ms 314704 KB Output is correct
2 Correct 1722 ms 314704 KB Output is correct
3 Execution timed out 3040 ms 357456 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2195 ms 314704 KB Output is correct
2 Correct 1722 ms 314704 KB Output is correct
3 Execution timed out 3040 ms 357456 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 29 ms 21596 KB Output is correct
2 Execution timed out 3053 ms 314712 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2195 ms 314704 KB Output is correct
2 Correct 1722 ms 314704 KB Output is correct
3 Execution timed out 3040 ms 357456 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2195 ms 314704 KB Output is correct
2 Correct 1722 ms 314704 KB Output is correct
3 Execution timed out 3040 ms 357456 KB Time limit exceeded
4 Halted 0 ms 0 KB -