Submission #286917

# Submission time Handle Problem Language Result Execution time Memory
286917 2020-08-31T07:08:25 Z AlexLuchianov Political Development (BOI17_politicaldevelopment) C++14
100 / 100
594 ms 27100 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <queue>
#include <set>

using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))

int const nmax = 50000;
std::set<int> g[1 + nmax];
int used[1 + nmax];
std::queue<int> q;

int solve(int node) {
  int sz = g[node].size();
  std::vector<int> neighbours;
  for(std::set<int>::iterator it = g[node].begin(); it != g[node].end(); it++)
    neighbours.push_back(*it);
  std::vector<int> dp(1 << sz, 1);
  dp[0] = 1;
  for(int i = 0; i < sz; i++)
    for(int j = i + 1; j < sz; j++)
      if(g[neighbours[i]].find(neighbours[j]) == g[neighbours[i]].end())
        dp[(1 << i) | (1 << j)] = 0;
  int result = 0;
  for(int mask = 1; mask < (1 << sz); mask++) {
    for(int j = 0; j < sz; j++)
      if(0 < ((1 << j) & mask))
        dp[mask] &= dp[mask ^ (1 << j)]; 
    if(dp[mask] == 1)
      result = std::max(result, __builtin_popcount(mask));
  }
  return result + 1;
}

int main() {
  int n, k;
  std::cin >> n >> k;
  for(int i = 0; i < n; i++) {
    int d;
    std::cin >> d;
    for(int j = 0; j < d; j++) {
      int val;
      std::cin >> val;
      g[i].insert(val);
    }
  }
  
  for(int i = 0; i < n; i++) {
    if(g[i].size() < k) {
      used[i] = 1;
      q.push(i);
    }
  }
  int result = 1;
  while(0 < q.size()) {
    int node = q.front();
    q.pop();
    result = std::max(result, solve(node));
    std::set<int>::iterator it = g[node].begin();
    while(it != g[node].end()) {
      int to = *it;
      g[to].erase(node);
      if(g[to].size() < k && used[to] == 0) {
        used[to] = 1;
        q.push(to);
      }
      it++;
    }
  }
  std::cout << result;
  return 0;
}

Compilation message

politicaldevelopment.cpp: In function 'int main()':
politicaldevelopment.cpp:54:20: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   54 |     if(g[i].size() < k) {
      |        ~~~~~~~~~~~~^~~
politicaldevelopment.cpp:68:23: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   68 |       if(g[to].size() < k && used[to] == 0) {
      |          ~~~~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Correct 13 ms 3200 KB Output is correct
4 Correct 10 ms 3232 KB Output is correct
5 Correct 11 ms 3200 KB Output is correct
6 Correct 12 ms 3200 KB Output is correct
7 Correct 12 ms 3200 KB Output is correct
8 Correct 4 ms 2688 KB Output is correct
9 Correct 3 ms 2688 KB Output is correct
10 Correct 4 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Correct 13 ms 3200 KB Output is correct
4 Correct 10 ms 3232 KB Output is correct
5 Correct 11 ms 3200 KB Output is correct
6 Correct 12 ms 3200 KB Output is correct
7 Correct 12 ms 3200 KB Output is correct
8 Correct 4 ms 2688 KB Output is correct
9 Correct 3 ms 2688 KB Output is correct
10 Correct 4 ms 2688 KB Output is correct
11 Correct 12 ms 3200 KB Output is correct
12 Correct 11 ms 3200 KB Output is correct
13 Correct 2 ms 2688 KB Output is correct
14 Correct 11 ms 3200 KB Output is correct
15 Correct 2 ms 2688 KB Output is correct
16 Correct 11 ms 3200 KB Output is correct
17 Correct 2 ms 2688 KB Output is correct
18 Correct 10 ms 3200 KB Output is correct
19 Correct 4 ms 2688 KB Output is correct
20 Correct 7 ms 2944 KB Output is correct
21 Correct 7 ms 2944 KB Output is correct
22 Correct 4 ms 2688 KB Output is correct
23 Correct 12 ms 3328 KB Output is correct
24 Correct 4 ms 2688 KB Output is correct
25 Correct 13 ms 3328 KB Output is correct
26 Correct 11 ms 3328 KB Output is correct
27 Correct 10 ms 3200 KB Output is correct
28 Correct 12 ms 3328 KB Output is correct
29 Correct 10 ms 3200 KB Output is correct
30 Correct 13 ms 3456 KB Output is correct
31 Correct 13 ms 3328 KB Output is correct
32 Correct 13 ms 3456 KB Output is correct
33 Correct 13 ms 3456 KB Output is correct
34 Correct 13 ms 3328 KB Output is correct
35 Correct 7 ms 3072 KB Output is correct
36 Correct 7 ms 3072 KB Output is correct
37 Correct 7 ms 3072 KB Output is correct
38 Correct 5 ms 2944 KB Output is correct
39 Correct 6 ms 2944 KB Output is correct
40 Correct 18 ms 3712 KB Output is correct
41 Correct 5 ms 2944 KB Output is correct
42 Correct 17 ms 3712 KB Output is correct
43 Correct 18 ms 3712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2688 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Correct 2 ms 2688 KB Output is correct
4 Correct 2 ms 2688 KB Output is correct
5 Correct 3 ms 2688 KB Output is correct
6 Correct 2 ms 2688 KB Output is correct
7 Correct 2 ms 2688 KB Output is correct
8 Correct 2 ms 2688 KB Output is correct
9 Correct 2 ms 2688 KB Output is correct
10 Correct 2 ms 2688 KB Output is correct
11 Correct 594 ms 27100 KB Output is correct
12 Correct 2 ms 2688 KB Output is correct
13 Correct 581 ms 26872 KB Output is correct
14 Correct 2 ms 2688 KB Output is correct
15 Correct 589 ms 27032 KB Output is correct
16 Correct 594 ms 26904 KB Output is correct
17 Correct 575 ms 26920 KB Output is correct
18 Correct 582 ms 27000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Correct 13 ms 3200 KB Output is correct
4 Correct 10 ms 3232 KB Output is correct
5 Correct 11 ms 3200 KB Output is correct
6 Correct 12 ms 3200 KB Output is correct
7 Correct 12 ms 3200 KB Output is correct
8 Correct 4 ms 2688 KB Output is correct
9 Correct 3 ms 2688 KB Output is correct
10 Correct 4 ms 2688 KB Output is correct
11 Correct 12 ms 3200 KB Output is correct
12 Correct 11 ms 3200 KB Output is correct
13 Correct 2 ms 2688 KB Output is correct
14 Correct 11 ms 3200 KB Output is correct
15 Correct 2 ms 2688 KB Output is correct
16 Correct 11 ms 3200 KB Output is correct
17 Correct 2 ms 2688 KB Output is correct
18 Correct 10 ms 3200 KB Output is correct
19 Correct 4 ms 2688 KB Output is correct
20 Correct 7 ms 2944 KB Output is correct
21 Correct 7 ms 2944 KB Output is correct
22 Correct 4 ms 2688 KB Output is correct
23 Correct 12 ms 3328 KB Output is correct
24 Correct 4 ms 2688 KB Output is correct
25 Correct 13 ms 3328 KB Output is correct
26 Correct 11 ms 3328 KB Output is correct
27 Correct 10 ms 3200 KB Output is correct
28 Correct 12 ms 3328 KB Output is correct
29 Correct 10 ms 3200 KB Output is correct
30 Correct 13 ms 3456 KB Output is correct
31 Correct 13 ms 3328 KB Output is correct
32 Correct 13 ms 3456 KB Output is correct
33 Correct 13 ms 3456 KB Output is correct
34 Correct 13 ms 3328 KB Output is correct
35 Correct 7 ms 3072 KB Output is correct
36 Correct 7 ms 3072 KB Output is correct
37 Correct 7 ms 3072 KB Output is correct
38 Correct 5 ms 2944 KB Output is correct
39 Correct 6 ms 2944 KB Output is correct
40 Correct 18 ms 3712 KB Output is correct
41 Correct 5 ms 2944 KB Output is correct
42 Correct 17 ms 3712 KB Output is correct
43 Correct 18 ms 3712 KB Output is correct
44 Correct 45 ms 4736 KB Output is correct
45 Correct 3 ms 2688 KB Output is correct
46 Correct 18 ms 3712 KB Output is correct
47 Correct 33 ms 4728 KB Output is correct
48 Correct 17 ms 3712 KB Output is correct
49 Correct 33 ms 4728 KB Output is correct
50 Correct 36 ms 4676 KB Output is correct
51 Correct 91 ms 6776 KB Output is correct
52 Correct 10 ms 3200 KB Output is correct
53 Correct 141 ms 7544 KB Output is correct
54 Correct 142 ms 7288 KB Output is correct
55 Correct 10 ms 3200 KB Output is correct
56 Correct 10 ms 3200 KB Output is correct
57 Correct 4 ms 2688 KB Output is correct
58 Correct 137 ms 7416 KB Output is correct
59 Correct 17 ms 3712 KB Output is correct
60 Correct 10 ms 3200 KB Output is correct
61 Correct 17 ms 3712 KB Output is correct
62 Correct 19 ms 3708 KB Output is correct
63 Correct 42 ms 4732 KB Output is correct
64 Correct 30 ms 4480 KB Output is correct
65 Correct 20 ms 3584 KB Output is correct
66 Correct 17 ms 3712 KB Output is correct
67 Correct 62 ms 5112 KB Output is correct
68 Correct 36 ms 4480 KB Output is correct
69 Correct 16 ms 3584 KB Output is correct
70 Correct 31 ms 4600 KB Output is correct
71 Correct 55 ms 5112 KB Output is correct
72 Correct 48 ms 5112 KB Output is correct
73 Correct 10 ms 3252 KB Output is correct
74 Correct 32 ms 4608 KB Output is correct
75 Correct 50 ms 5112 KB Output is correct
76 Correct 23 ms 4096 KB Output is correct
77 Correct 70 ms 5624 KB Output is correct
78 Correct 10 ms 3200 KB Output is correct
79 Correct 35 ms 4216 KB Output is correct
80 Correct 24 ms 4092 KB Output is correct
81 Correct 76 ms 5624 KB Output is correct
82 Correct 6 ms 2944 KB Output is correct
83 Correct 34 ms 4216 KB Output is correct
84 Correct 52 ms 4984 KB Output is correct
85 Correct 6 ms 2944 KB Output is correct
86 Correct 50 ms 4984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Correct 13 ms 3200 KB Output is correct
4 Correct 10 ms 3232 KB Output is correct
5 Correct 11 ms 3200 KB Output is correct
6 Correct 12 ms 3200 KB Output is correct
7 Correct 12 ms 3200 KB Output is correct
8 Correct 4 ms 2688 KB Output is correct
9 Correct 3 ms 2688 KB Output is correct
10 Correct 4 ms 2688 KB Output is correct
11 Correct 12 ms 3200 KB Output is correct
12 Correct 11 ms 3200 KB Output is correct
13 Correct 2 ms 2688 KB Output is correct
14 Correct 11 ms 3200 KB Output is correct
15 Correct 2 ms 2688 KB Output is correct
16 Correct 11 ms 3200 KB Output is correct
17 Correct 2 ms 2688 KB Output is correct
18 Correct 10 ms 3200 KB Output is correct
19 Correct 4 ms 2688 KB Output is correct
20 Correct 7 ms 2944 KB Output is correct
21 Correct 7 ms 2944 KB Output is correct
22 Correct 4 ms 2688 KB Output is correct
23 Correct 12 ms 3328 KB Output is correct
24 Correct 4 ms 2688 KB Output is correct
25 Correct 13 ms 3328 KB Output is correct
26 Correct 11 ms 3328 KB Output is correct
27 Correct 10 ms 3200 KB Output is correct
28 Correct 12 ms 3328 KB Output is correct
29 Correct 10 ms 3200 KB Output is correct
30 Correct 13 ms 3456 KB Output is correct
31 Correct 13 ms 3328 KB Output is correct
32 Correct 13 ms 3456 KB Output is correct
33 Correct 13 ms 3456 KB Output is correct
34 Correct 13 ms 3328 KB Output is correct
35 Correct 7 ms 3072 KB Output is correct
36 Correct 7 ms 3072 KB Output is correct
37 Correct 7 ms 3072 KB Output is correct
38 Correct 5 ms 2944 KB Output is correct
39 Correct 6 ms 2944 KB Output is correct
40 Correct 18 ms 3712 KB Output is correct
41 Correct 5 ms 2944 KB Output is correct
42 Correct 17 ms 3712 KB Output is correct
43 Correct 18 ms 3712 KB Output is correct
44 Correct 2 ms 2688 KB Output is correct
45 Correct 336 ms 18808 KB Output is correct
46 Correct 148 ms 11000 KB Output is correct
47 Correct 286 ms 18808 KB Output is correct
48 Correct 304 ms 18808 KB Output is correct
49 Correct 100 ms 8568 KB Output is correct
50 Correct 404 ms 24412 KB Output is correct
51 Correct 302 ms 18880 KB Output is correct
52 Correct 96 ms 8440 KB Output is correct
53 Correct 106 ms 8444 KB Output is correct
54 Correct 17 ms 3200 KB Output is correct
55 Correct 402 ms 24312 KB Output is correct
56 Correct 55 ms 5752 KB Output is correct
57 Correct 95 ms 8440 KB Output is correct
58 Correct 145 ms 11124 KB Output is correct
59 Correct 55 ms 5752 KB Output is correct
60 Correct 56 ms 5752 KB Output is correct
61 Correct 143 ms 11128 KB Output is correct
62 Correct 101 ms 8568 KB Output is correct
63 Correct 177 ms 12280 KB Output is correct
64 Correct 55 ms 5752 KB Output is correct
65 Correct 218 ms 14968 KB Output is correct
66 Correct 95 ms 8440 KB Output is correct
67 Correct 175 ms 12284 KB Output is correct
68 Correct 220 ms 14332 KB Output is correct
69 Correct 216 ms 14968 KB Output is correct
70 Correct 95 ms 8440 KB Output is correct
71 Correct 213 ms 14328 KB Output is correct
72 Correct 170 ms 12152 KB Output is correct
73 Correct 250 ms 16504 KB Output is correct
74 Correct 98 ms 8440 KB Output is correct
75 Correct 91 ms 7928 KB Output is correct
76 Correct 170 ms 12024 KB Output is correct
77 Correct 253 ms 16632 KB Output is correct
78 Correct 119 ms 9592 KB Output is correct
79 Correct 92 ms 7932 KB Output is correct
80 Correct 46 ms 5368 KB Output is correct
81 Correct 119 ms 9592 KB Output is correct
82 Correct 201 ms 13688 KB Output is correct
83 Correct 42 ms 5368 KB Output is correct
84 Correct 233 ms 13816 KB Output is correct