#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <unordered_set>
using namespace std;
using namespace __gnu_pbds;
template<typename T>
using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
// const ll M = 998244353;
const ll M = 1e9 + 7;
#define all(v) (v).begin(), (v).end()
#define ff first
#define ss second
const ll INFL = 1e18;
const int INF = 1e9;
const int maxN = 50000;
bool dp[maxN][1<<10];
unordered_set<int> adj[maxN];
void solve() {
int n, k;
cin >> n >> k;
for (int i=0; i<n; i++) {
int d;
cin >> d;
for (int j=0; j<d; j++) {
int x;
cin >> x;
adj[i].insert(x);
}
}
vector<int> ord(n);
iota(all(ord), 0);
sort(all(ord), [](int l, int r) {
return adj[l].size() < adj[r].size();
});
int ans = 1;
for (auto i : ord) {
vector<int> cur;
for (auto v: adj[i]) cur.push_back(v);
dp[i][0] = true;
for (int msk=1; msk<1<<cur.size(); msk++) {
int p = __lg(msk);
bool ok = dp[i][msk^(1<<p)];
for (int j=0; j<p; j++) {
if (!(msk&(1<<j))) continue;
ok &= adj[cur[j]].count(cur[p]);
}
dp[i][msk] = ok;
if (ok) {
ans = max(ans, __builtin_popcount(msk)+1);
}
}
for (auto v: cur) adj[v].erase(i);
}
cout << ans << '\n';
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(NULL);
// cout << setprecision(12);
int tc = 1;
// cin >> tc;
while (tc--) solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3164 KB |
Output is correct |
2 |
Correct |
1 ms |
3216 KB |
Output is correct |
3 |
Correct |
5 ms |
8900 KB |
Output is correct |
4 |
Correct |
6 ms |
9052 KB |
Output is correct |
5 |
Correct |
6 ms |
9144 KB |
Output is correct |
6 |
Correct |
5 ms |
9052 KB |
Output is correct |
7 |
Correct |
6 ms |
9084 KB |
Output is correct |
8 |
Correct |
5 ms |
8028 KB |
Output is correct |
9 |
Correct |
2 ms |
3164 KB |
Output is correct |
10 |
Correct |
3 ms |
8028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3164 KB |
Output is correct |
2 |
Correct |
1 ms |
3216 KB |
Output is correct |
3 |
Correct |
5 ms |
8900 KB |
Output is correct |
4 |
Correct |
6 ms |
9052 KB |
Output is correct |
5 |
Correct |
6 ms |
9144 KB |
Output is correct |
6 |
Correct |
5 ms |
9052 KB |
Output is correct |
7 |
Correct |
6 ms |
9084 KB |
Output is correct |
8 |
Correct |
5 ms |
8028 KB |
Output is correct |
9 |
Correct |
2 ms |
3164 KB |
Output is correct |
10 |
Correct |
3 ms |
8028 KB |
Output is correct |
11 |
Correct |
5 ms |
9052 KB |
Output is correct |
12 |
Correct |
4 ms |
9052 KB |
Output is correct |
13 |
Correct |
2 ms |
3164 KB |
Output is correct |
14 |
Correct |
6 ms |
9052 KB |
Output is correct |
15 |
Correct |
1 ms |
3164 KB |
Output is correct |
16 |
Correct |
6 ms |
9052 KB |
Output is correct |
17 |
Correct |
1 ms |
3164 KB |
Output is correct |
18 |
Correct |
5 ms |
9052 KB |
Output is correct |
19 |
Correct |
4 ms |
8228 KB |
Output is correct |
20 |
Correct |
4 ms |
8796 KB |
Output is correct |
21 |
Correct |
4 ms |
8796 KB |
Output is correct |
22 |
Correct |
3 ms |
8024 KB |
Output is correct |
23 |
Correct |
6 ms |
9052 KB |
Output is correct |
24 |
Correct |
3 ms |
8028 KB |
Output is correct |
25 |
Correct |
7 ms |
9052 KB |
Output is correct |
26 |
Correct |
6 ms |
9052 KB |
Output is correct |
27 |
Correct |
5 ms |
9052 KB |
Output is correct |
28 |
Correct |
6 ms |
8876 KB |
Output is correct |
29 |
Correct |
4 ms |
9052 KB |
Output is correct |
30 |
Correct |
6 ms |
9052 KB |
Output is correct |
31 |
Correct |
5 ms |
9052 KB |
Output is correct |
32 |
Correct |
8 ms |
9052 KB |
Output is correct |
33 |
Correct |
6 ms |
9052 KB |
Output is correct |
34 |
Correct |
5 ms |
9048 KB |
Output is correct |
35 |
Correct |
4 ms |
5980 KB |
Output is correct |
36 |
Correct |
4 ms |
5980 KB |
Output is correct |
37 |
Correct |
4 ms |
6036 KB |
Output is correct |
38 |
Correct |
3 ms |
4700 KB |
Output is correct |
39 |
Correct |
2 ms |
4700 KB |
Output is correct |
40 |
Correct |
9 ms |
9304 KB |
Output is correct |
41 |
Correct |
3 ms |
4700 KB |
Output is correct |
42 |
Correct |
8 ms |
9308 KB |
Output is correct |
43 |
Correct |
7 ms |
9308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
8028 KB |
Output is correct |
2 |
Correct |
1 ms |
3164 KB |
Output is correct |
3 |
Correct |
1 ms |
3164 KB |
Output is correct |
4 |
Correct |
1 ms |
2992 KB |
Output is correct |
5 |
Correct |
2 ms |
3164 KB |
Output is correct |
6 |
Correct |
1 ms |
3164 KB |
Output is correct |
7 |
Correct |
1 ms |
3164 KB |
Output is correct |
8 |
Correct |
1 ms |
3164 KB |
Output is correct |
9 |
Correct |
2 ms |
3416 KB |
Output is correct |
10 |
Correct |
1 ms |
3164 KB |
Output is correct |
11 |
Correct |
320 ms |
72992 KB |
Output is correct |
12 |
Correct |
2 ms |
3164 KB |
Output is correct |
13 |
Correct |
318 ms |
73044 KB |
Output is correct |
14 |
Correct |
2 ms |
3160 KB |
Output is correct |
15 |
Correct |
308 ms |
72856 KB |
Output is correct |
16 |
Correct |
320 ms |
72848 KB |
Output is correct |
17 |
Correct |
328 ms |
72996 KB |
Output is correct |
18 |
Correct |
314 ms |
73040 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3164 KB |
Output is correct |
2 |
Correct |
1 ms |
3216 KB |
Output is correct |
3 |
Correct |
5 ms |
8900 KB |
Output is correct |
4 |
Correct |
6 ms |
9052 KB |
Output is correct |
5 |
Correct |
6 ms |
9144 KB |
Output is correct |
6 |
Correct |
5 ms |
9052 KB |
Output is correct |
7 |
Correct |
6 ms |
9084 KB |
Output is correct |
8 |
Correct |
5 ms |
8028 KB |
Output is correct |
9 |
Correct |
2 ms |
3164 KB |
Output is correct |
10 |
Correct |
3 ms |
8028 KB |
Output is correct |
11 |
Correct |
5 ms |
9052 KB |
Output is correct |
12 |
Correct |
4 ms |
9052 KB |
Output is correct |
13 |
Correct |
2 ms |
3164 KB |
Output is correct |
14 |
Correct |
6 ms |
9052 KB |
Output is correct |
15 |
Correct |
1 ms |
3164 KB |
Output is correct |
16 |
Correct |
6 ms |
9052 KB |
Output is correct |
17 |
Correct |
1 ms |
3164 KB |
Output is correct |
18 |
Correct |
5 ms |
9052 KB |
Output is correct |
19 |
Correct |
4 ms |
8228 KB |
Output is correct |
20 |
Correct |
4 ms |
8796 KB |
Output is correct |
21 |
Correct |
4 ms |
8796 KB |
Output is correct |
22 |
Correct |
3 ms |
8024 KB |
Output is correct |
23 |
Correct |
6 ms |
9052 KB |
Output is correct |
24 |
Correct |
3 ms |
8028 KB |
Output is correct |
25 |
Correct |
7 ms |
9052 KB |
Output is correct |
26 |
Correct |
6 ms |
9052 KB |
Output is correct |
27 |
Correct |
5 ms |
9052 KB |
Output is correct |
28 |
Correct |
6 ms |
8876 KB |
Output is correct |
29 |
Correct |
4 ms |
9052 KB |
Output is correct |
30 |
Correct |
6 ms |
9052 KB |
Output is correct |
31 |
Correct |
5 ms |
9052 KB |
Output is correct |
32 |
Correct |
8 ms |
9052 KB |
Output is correct |
33 |
Correct |
6 ms |
9052 KB |
Output is correct |
34 |
Correct |
5 ms |
9048 KB |
Output is correct |
35 |
Correct |
4 ms |
5980 KB |
Output is correct |
36 |
Correct |
4 ms |
5980 KB |
Output is correct |
37 |
Correct |
4 ms |
6036 KB |
Output is correct |
38 |
Correct |
3 ms |
4700 KB |
Output is correct |
39 |
Correct |
2 ms |
4700 KB |
Output is correct |
40 |
Correct |
9 ms |
9304 KB |
Output is correct |
41 |
Correct |
3 ms |
4700 KB |
Output is correct |
42 |
Correct |
8 ms |
9308 KB |
Output is correct |
43 |
Correct |
7 ms |
9308 KB |
Output is correct |
44 |
Correct |
15 ms |
9816 KB |
Output is correct |
45 |
Correct |
1 ms |
3164 KB |
Output is correct |
46 |
Correct |
6 ms |
9232 KB |
Output is correct |
47 |
Correct |
13 ms |
10080 KB |
Output is correct |
48 |
Correct |
7 ms |
9308 KB |
Output is correct |
49 |
Correct |
13 ms |
10076 KB |
Output is correct |
50 |
Correct |
16 ms |
10032 KB |
Output is correct |
51 |
Correct |
365 ms |
11600 KB |
Output is correct |
52 |
Correct |
5 ms |
9048 KB |
Output is correct |
53 |
Correct |
40 ms |
11800 KB |
Output is correct |
54 |
Correct |
2192 ms |
27220 KB |
Output is correct |
55 |
Correct |
5 ms |
9052 KB |
Output is correct |
56 |
Correct |
5 ms |
9052 KB |
Output is correct |
57 |
Correct |
3 ms |
8028 KB |
Output is correct |
58 |
Correct |
44 ms |
11832 KB |
Output is correct |
59 |
Correct |
8 ms |
9308 KB |
Output is correct |
60 |
Correct |
5 ms |
9028 KB |
Output is correct |
61 |
Correct |
6 ms |
9388 KB |
Output is correct |
62 |
Correct |
10 ms |
9304 KB |
Output is correct |
63 |
Correct |
13 ms |
9820 KB |
Output is correct |
64 |
Correct |
10 ms |
9644 KB |
Output is correct |
65 |
Correct |
6 ms |
9180 KB |
Output is correct |
66 |
Correct |
6 ms |
9412 KB |
Output is correct |
67 |
Correct |
30 ms |
10408 KB |
Output is correct |
68 |
Correct |
12 ms |
9672 KB |
Output is correct |
69 |
Correct |
6 ms |
9308 KB |
Output is correct |
70 |
Correct |
13 ms |
9820 KB |
Output is correct |
71 |
Correct |
29 ms |
10376 KB |
Output is correct |
72 |
Correct |
30 ms |
10076 KB |
Output is correct |
73 |
Correct |
8 ms |
8948 KB |
Output is correct |
74 |
Correct |
12 ms |
9816 KB |
Output is correct |
75 |
Correct |
24 ms |
10328 KB |
Output is correct |
76 |
Correct |
8 ms |
9564 KB |
Output is correct |
77 |
Correct |
56 ms |
10624 KB |
Output is correct |
78 |
Correct |
7 ms |
9052 KB |
Output is correct |
79 |
Correct |
31 ms |
6748 KB |
Output is correct |
80 |
Correct |
9 ms |
9560 KB |
Output is correct |
81 |
Correct |
56 ms |
10540 KB |
Output is correct |
82 |
Correct |
3 ms |
4700 KB |
Output is correct |
83 |
Correct |
30 ms |
6876 KB |
Output is correct |
84 |
Correct |
32 ms |
9940 KB |
Output is correct |
85 |
Correct |
3 ms |
4700 KB |
Output is correct |
86 |
Correct |
43 ms |
9920 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3164 KB |
Output is correct |
2 |
Correct |
1 ms |
3216 KB |
Output is correct |
3 |
Correct |
5 ms |
8900 KB |
Output is correct |
4 |
Correct |
6 ms |
9052 KB |
Output is correct |
5 |
Correct |
6 ms |
9144 KB |
Output is correct |
6 |
Correct |
5 ms |
9052 KB |
Output is correct |
7 |
Correct |
6 ms |
9084 KB |
Output is correct |
8 |
Correct |
5 ms |
8028 KB |
Output is correct |
9 |
Correct |
2 ms |
3164 KB |
Output is correct |
10 |
Correct |
3 ms |
8028 KB |
Output is correct |
11 |
Correct |
5 ms |
9052 KB |
Output is correct |
12 |
Correct |
4 ms |
9052 KB |
Output is correct |
13 |
Correct |
2 ms |
3164 KB |
Output is correct |
14 |
Correct |
6 ms |
9052 KB |
Output is correct |
15 |
Correct |
1 ms |
3164 KB |
Output is correct |
16 |
Correct |
6 ms |
9052 KB |
Output is correct |
17 |
Correct |
1 ms |
3164 KB |
Output is correct |
18 |
Correct |
5 ms |
9052 KB |
Output is correct |
19 |
Correct |
4 ms |
8228 KB |
Output is correct |
20 |
Correct |
4 ms |
8796 KB |
Output is correct |
21 |
Correct |
4 ms |
8796 KB |
Output is correct |
22 |
Correct |
3 ms |
8024 KB |
Output is correct |
23 |
Correct |
6 ms |
9052 KB |
Output is correct |
24 |
Correct |
3 ms |
8028 KB |
Output is correct |
25 |
Correct |
7 ms |
9052 KB |
Output is correct |
26 |
Correct |
6 ms |
9052 KB |
Output is correct |
27 |
Correct |
5 ms |
9052 KB |
Output is correct |
28 |
Correct |
6 ms |
8876 KB |
Output is correct |
29 |
Correct |
4 ms |
9052 KB |
Output is correct |
30 |
Correct |
6 ms |
9052 KB |
Output is correct |
31 |
Correct |
5 ms |
9052 KB |
Output is correct |
32 |
Correct |
8 ms |
9052 KB |
Output is correct |
33 |
Correct |
6 ms |
9052 KB |
Output is correct |
34 |
Correct |
5 ms |
9048 KB |
Output is correct |
35 |
Correct |
4 ms |
5980 KB |
Output is correct |
36 |
Correct |
4 ms |
5980 KB |
Output is correct |
37 |
Correct |
4 ms |
6036 KB |
Output is correct |
38 |
Correct |
3 ms |
4700 KB |
Output is correct |
39 |
Correct |
2 ms |
4700 KB |
Output is correct |
40 |
Correct |
9 ms |
9304 KB |
Output is correct |
41 |
Correct |
3 ms |
4700 KB |
Output is correct |
42 |
Correct |
8 ms |
9308 KB |
Output is correct |
43 |
Correct |
7 ms |
9308 KB |
Output is correct |
44 |
Correct |
1 ms |
3164 KB |
Output is correct |
45 |
Correct |
84 ms |
68488 KB |
Output is correct |
46 |
Correct |
74 ms |
63748 KB |
Output is correct |
47 |
Correct |
97 ms |
68624 KB |
Output is correct |
48 |
Correct |
96 ms |
68576 KB |
Output is correct |
49 |
Correct |
45 ms |
62560 KB |
Output is correct |
50 |
Correct |
99 ms |
73924 KB |
Output is correct |
51 |
Correct |
92 ms |
68428 KB |
Output is correct |
52 |
Correct |
45 ms |
62288 KB |
Output is correct |
53 |
Correct |
41 ms |
62704 KB |
Output is correct |
54 |
Correct |
20 ms |
53336 KB |
Output is correct |
55 |
Correct |
123 ms |
74032 KB |
Output is correct |
56 |
Correct |
34 ms |
60496 KB |
Output is correct |
57 |
Correct |
48 ms |
62292 KB |
Output is correct |
58 |
Correct |
53 ms |
63568 KB |
Output is correct |
59 |
Correct |
38 ms |
60500 KB |
Output is correct |
60 |
Correct |
34 ms |
60500 KB |
Output is correct |
61 |
Correct |
47 ms |
63568 KB |
Output is correct |
62 |
Correct |
45 ms |
62036 KB |
Output is correct |
63 |
Correct |
65 ms |
64340 KB |
Output is correct |
64 |
Correct |
43 ms |
60512 KB |
Output is correct |
65 |
Correct |
70 ms |
65928 KB |
Output is correct |
66 |
Correct |
41 ms |
62036 KB |
Output is correct |
67 |
Correct |
59 ms |
64204 KB |
Output is correct |
68 |
Correct |
64 ms |
65364 KB |
Output is correct |
69 |
Correct |
66 ms |
65872 KB |
Output is correct |
70 |
Correct |
41 ms |
62032 KB |
Output is correct |
71 |
Correct |
65 ms |
65520 KB |
Output is correct |
72 |
Correct |
63 ms |
64336 KB |
Output is correct |
73 |
Correct |
84 ms |
66896 KB |
Output is correct |
74 |
Correct |
45 ms |
61868 KB |
Output is correct |
75 |
Correct |
29 ms |
34136 KB |
Output is correct |
76 |
Correct |
62 ms |
64308 KB |
Output is correct |
77 |
Correct |
78 ms |
66900 KB |
Output is correct |
78 |
Correct |
35 ms |
35028 KB |
Output is correct |
79 |
Correct |
36 ms |
33872 KB |
Output is correct |
80 |
Correct |
17 ms |
18780 KB |
Output is correct |
81 |
Correct |
41 ms |
34900 KB |
Output is correct |
82 |
Correct |
55 ms |
65108 KB |
Output is correct |
83 |
Correct |
17 ms |
18780 KB |
Output is correct |
84 |
Correct |
58 ms |
65128 KB |
Output is correct |