#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
const int MAXN = 5e4 + 10;
int n, k;
vector<int> adj[MAXN];
void merge(vector<int>& v1, vector<int>& v2, vector<int>& res) {
int n = v1.size(), m = v2.size();
int p1 = 0, p2 = 0;
while ((p1 < n) && (p2 < m)) {
if (v1[p1] == v2[p2]) {
res.push_back(v1[p1]);
p1++;
p2++;
continue;
}
if (v1[p1] > v2[p2]) p1++;
else p2++;
}
}
int best(vector<int> pos) {
int mx = 0;
while (!pos.empty()) {
auto u = pos.back();
pos.pop_back();
vector<int> nxt;
merge(pos, adj[u], nxt);
mx = max(mx, 1 + best(nxt));
}
return mx;
}
int32_t main() {
cin >> n >> k;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
while (x--) {
int v;
cin >> v;
adj[i].push_back(v);
}
//sort(adj[i].begin(), adj[i].end(), greater<int>());
}
int ans = 0;
for (int i = 0; i < n; i++) {
ans = max(ans, best(adj[i]) + 1);
if (ans == k) break;
}
cout << ans << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1616 KB |
Output is correct |
2 |
Correct |
1 ms |
1616 KB |
Output is correct |
3 |
Correct |
3 ms |
1616 KB |
Output is correct |
4 |
Correct |
4 ms |
1616 KB |
Output is correct |
5 |
Correct |
4 ms |
1616 KB |
Output is correct |
6 |
Correct |
3 ms |
1616 KB |
Output is correct |
7 |
Correct |
4 ms |
1616 KB |
Output is correct |
8 |
Correct |
2 ms |
1360 KB |
Output is correct |
9 |
Correct |
2 ms |
1512 KB |
Output is correct |
10 |
Correct |
2 ms |
1616 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1616 KB |
Output is correct |
2 |
Correct |
1 ms |
1616 KB |
Output is correct |
3 |
Correct |
3 ms |
1616 KB |
Output is correct |
4 |
Correct |
4 ms |
1616 KB |
Output is correct |
5 |
Correct |
4 ms |
1616 KB |
Output is correct |
6 |
Correct |
3 ms |
1616 KB |
Output is correct |
7 |
Correct |
4 ms |
1616 KB |
Output is correct |
8 |
Correct |
2 ms |
1360 KB |
Output is correct |
9 |
Correct |
2 ms |
1512 KB |
Output is correct |
10 |
Correct |
2 ms |
1616 KB |
Output is correct |
11 |
Correct |
4 ms |
1616 KB |
Output is correct |
12 |
Correct |
4 ms |
1784 KB |
Output is correct |
13 |
Correct |
1 ms |
1616 KB |
Output is correct |
14 |
Correct |
4 ms |
1616 KB |
Output is correct |
15 |
Correct |
2 ms |
1360 KB |
Output is correct |
16 |
Correct |
4 ms |
1616 KB |
Output is correct |
17 |
Correct |
1 ms |
1616 KB |
Output is correct |
18 |
Correct |
4 ms |
1616 KB |
Output is correct |
19 |
Correct |
2 ms |
1616 KB |
Output is correct |
20 |
Correct |
4 ms |
1616 KB |
Output is correct |
21 |
Correct |
3 ms |
1616 KB |
Output is correct |
22 |
Correct |
2 ms |
1360 KB |
Output is correct |
23 |
Correct |
4 ms |
1616 KB |
Output is correct |
24 |
Correct |
2 ms |
1616 KB |
Output is correct |
25 |
Correct |
5 ms |
1616 KB |
Output is correct |
26 |
Correct |
4 ms |
1616 KB |
Output is correct |
27 |
Correct |
4 ms |
1616 KB |
Output is correct |
28 |
Correct |
4 ms |
1616 KB |
Output is correct |
29 |
Correct |
4 ms |
1616 KB |
Output is correct |
30 |
Correct |
4 ms |
1788 KB |
Output is correct |
31 |
Correct |
5 ms |
1616 KB |
Output is correct |
32 |
Correct |
5 ms |
1784 KB |
Output is correct |
33 |
Correct |
5 ms |
1616 KB |
Output is correct |
34 |
Correct |
8 ms |
1616 KB |
Output is correct |
35 |
Correct |
3 ms |
1616 KB |
Output is correct |
36 |
Correct |
4 ms |
1616 KB |
Output is correct |
37 |
Correct |
4 ms |
1616 KB |
Output is correct |
38 |
Correct |
3 ms |
1616 KB |
Output is correct |
39 |
Correct |
5 ms |
1616 KB |
Output is correct |
40 |
Correct |
6 ms |
1616 KB |
Output is correct |
41 |
Correct |
3 ms |
1616 KB |
Output is correct |
42 |
Correct |
6 ms |
1616 KB |
Output is correct |
43 |
Correct |
6 ms |
1616 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
1784 KB |
Output is correct |
2 |
Correct |
2 ms |
1616 KB |
Output is correct |
3 |
Correct |
2 ms |
1616 KB |
Output is correct |
4 |
Correct |
2 ms |
1360 KB |
Output is correct |
5 |
Correct |
2 ms |
1616 KB |
Output is correct |
6 |
Correct |
2 ms |
1360 KB |
Output is correct |
7 |
Correct |
2 ms |
1616 KB |
Output is correct |
8 |
Correct |
2 ms |
1372 KB |
Output is correct |
9 |
Correct |
2 ms |
1360 KB |
Output is correct |
10 |
Correct |
2 ms |
1360 KB |
Output is correct |
11 |
Correct |
111 ms |
5452 KB |
Output is correct |
12 |
Correct |
2 ms |
1360 KB |
Output is correct |
13 |
Correct |
112 ms |
5368 KB |
Output is correct |
14 |
Correct |
2 ms |
1616 KB |
Output is correct |
15 |
Correct |
116 ms |
5508 KB |
Output is correct |
16 |
Correct |
110 ms |
5448 KB |
Output is correct |
17 |
Correct |
120 ms |
5456 KB |
Output is correct |
18 |
Correct |
117 ms |
5448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1616 KB |
Output is correct |
2 |
Correct |
1 ms |
1616 KB |
Output is correct |
3 |
Correct |
3 ms |
1616 KB |
Output is correct |
4 |
Correct |
4 ms |
1616 KB |
Output is correct |
5 |
Correct |
4 ms |
1616 KB |
Output is correct |
6 |
Correct |
3 ms |
1616 KB |
Output is correct |
7 |
Correct |
4 ms |
1616 KB |
Output is correct |
8 |
Correct |
2 ms |
1360 KB |
Output is correct |
9 |
Correct |
2 ms |
1512 KB |
Output is correct |
10 |
Correct |
2 ms |
1616 KB |
Output is correct |
11 |
Correct |
4 ms |
1616 KB |
Output is correct |
12 |
Correct |
4 ms |
1784 KB |
Output is correct |
13 |
Correct |
1 ms |
1616 KB |
Output is correct |
14 |
Correct |
4 ms |
1616 KB |
Output is correct |
15 |
Correct |
2 ms |
1360 KB |
Output is correct |
16 |
Correct |
4 ms |
1616 KB |
Output is correct |
17 |
Correct |
1 ms |
1616 KB |
Output is correct |
18 |
Correct |
4 ms |
1616 KB |
Output is correct |
19 |
Correct |
2 ms |
1616 KB |
Output is correct |
20 |
Correct |
4 ms |
1616 KB |
Output is correct |
21 |
Correct |
3 ms |
1616 KB |
Output is correct |
22 |
Correct |
2 ms |
1360 KB |
Output is correct |
23 |
Correct |
4 ms |
1616 KB |
Output is correct |
24 |
Correct |
2 ms |
1616 KB |
Output is correct |
25 |
Correct |
5 ms |
1616 KB |
Output is correct |
26 |
Correct |
4 ms |
1616 KB |
Output is correct |
27 |
Correct |
4 ms |
1616 KB |
Output is correct |
28 |
Correct |
4 ms |
1616 KB |
Output is correct |
29 |
Correct |
4 ms |
1616 KB |
Output is correct |
30 |
Correct |
4 ms |
1788 KB |
Output is correct |
31 |
Correct |
5 ms |
1616 KB |
Output is correct |
32 |
Correct |
5 ms |
1784 KB |
Output is correct |
33 |
Correct |
5 ms |
1616 KB |
Output is correct |
34 |
Correct |
8 ms |
1616 KB |
Output is correct |
35 |
Correct |
3 ms |
1616 KB |
Output is correct |
36 |
Correct |
4 ms |
1616 KB |
Output is correct |
37 |
Correct |
4 ms |
1616 KB |
Output is correct |
38 |
Correct |
3 ms |
1616 KB |
Output is correct |
39 |
Correct |
5 ms |
1616 KB |
Output is correct |
40 |
Correct |
6 ms |
1616 KB |
Output is correct |
41 |
Correct |
3 ms |
1616 KB |
Output is correct |
42 |
Correct |
6 ms |
1616 KB |
Output is correct |
43 |
Correct |
6 ms |
1616 KB |
Output is correct |
44 |
Correct |
8 ms |
1616 KB |
Output is correct |
45 |
Correct |
2 ms |
1616 KB |
Output is correct |
46 |
Correct |
6 ms |
1616 KB |
Output is correct |
47 |
Incorrect |
10 ms |
1872 KB |
Output isn't correct |
48 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1616 KB |
Output is correct |
2 |
Correct |
1 ms |
1616 KB |
Output is correct |
3 |
Correct |
3 ms |
1616 KB |
Output is correct |
4 |
Correct |
4 ms |
1616 KB |
Output is correct |
5 |
Correct |
4 ms |
1616 KB |
Output is correct |
6 |
Correct |
3 ms |
1616 KB |
Output is correct |
7 |
Correct |
4 ms |
1616 KB |
Output is correct |
8 |
Correct |
2 ms |
1360 KB |
Output is correct |
9 |
Correct |
2 ms |
1512 KB |
Output is correct |
10 |
Correct |
2 ms |
1616 KB |
Output is correct |
11 |
Correct |
4 ms |
1616 KB |
Output is correct |
12 |
Correct |
4 ms |
1784 KB |
Output is correct |
13 |
Correct |
1 ms |
1616 KB |
Output is correct |
14 |
Correct |
4 ms |
1616 KB |
Output is correct |
15 |
Correct |
2 ms |
1360 KB |
Output is correct |
16 |
Correct |
4 ms |
1616 KB |
Output is correct |
17 |
Correct |
1 ms |
1616 KB |
Output is correct |
18 |
Correct |
4 ms |
1616 KB |
Output is correct |
19 |
Correct |
2 ms |
1616 KB |
Output is correct |
20 |
Correct |
4 ms |
1616 KB |
Output is correct |
21 |
Correct |
3 ms |
1616 KB |
Output is correct |
22 |
Correct |
2 ms |
1360 KB |
Output is correct |
23 |
Correct |
4 ms |
1616 KB |
Output is correct |
24 |
Correct |
2 ms |
1616 KB |
Output is correct |
25 |
Correct |
5 ms |
1616 KB |
Output is correct |
26 |
Correct |
4 ms |
1616 KB |
Output is correct |
27 |
Correct |
4 ms |
1616 KB |
Output is correct |
28 |
Correct |
4 ms |
1616 KB |
Output is correct |
29 |
Correct |
4 ms |
1616 KB |
Output is correct |
30 |
Correct |
4 ms |
1788 KB |
Output is correct |
31 |
Correct |
5 ms |
1616 KB |
Output is correct |
32 |
Correct |
5 ms |
1784 KB |
Output is correct |
33 |
Correct |
5 ms |
1616 KB |
Output is correct |
34 |
Correct |
8 ms |
1616 KB |
Output is correct |
35 |
Correct |
3 ms |
1616 KB |
Output is correct |
36 |
Correct |
4 ms |
1616 KB |
Output is correct |
37 |
Correct |
4 ms |
1616 KB |
Output is correct |
38 |
Correct |
3 ms |
1616 KB |
Output is correct |
39 |
Correct |
5 ms |
1616 KB |
Output is correct |
40 |
Correct |
6 ms |
1616 KB |
Output is correct |
41 |
Correct |
3 ms |
1616 KB |
Output is correct |
42 |
Correct |
6 ms |
1616 KB |
Output is correct |
43 |
Correct |
6 ms |
1616 KB |
Output is correct |
44 |
Correct |
2 ms |
1616 KB |
Output is correct |
45 |
Correct |
79 ms |
3764 KB |
Output is correct |
46 |
Correct |
43 ms |
3144 KB |
Output is correct |
47 |
Correct |
76 ms |
3880 KB |
Output is correct |
48 |
Correct |
65 ms |
3916 KB |
Output is correct |
49 |
Correct |
25 ms |
3268 KB |
Output is correct |
50 |
Correct |
90 ms |
4132 KB |
Output is correct |
51 |
Correct |
73 ms |
5732 KB |
Output is correct |
52 |
Correct |
25 ms |
3932 KB |
Output is correct |
53 |
Correct |
23 ms |
4044 KB |
Output is correct |
54 |
Correct |
6 ms |
1624 KB |
Output is correct |
55 |
Correct |
80 ms |
6472 KB |
Output is correct |
56 |
Correct |
19 ms |
3436 KB |
Output is correct |
57 |
Correct |
26 ms |
3912 KB |
Output is correct |
58 |
Correct |
46 ms |
3912 KB |
Output is correct |
59 |
Correct |
16 ms |
3408 KB |
Output is correct |
60 |
Correct |
17 ms |
3408 KB |
Output is correct |
61 |
Correct |
40 ms |
3864 KB |
Output is correct |
62 |
Correct |
29 ms |
3660 KB |
Output is correct |
63 |
Correct |
41 ms |
4448 KB |
Output is correct |
64 |
Correct |
17 ms |
3408 KB |
Output is correct |
65 |
Correct |
47 ms |
4936 KB |
Output is correct |
66 |
Correct |
29 ms |
3656 KB |
Output is correct |
67 |
Correct |
44 ms |
4424 KB |
Output is correct |
68 |
Correct |
54 ms |
4680 KB |
Output is correct |
69 |
Correct |
47 ms |
4936 KB |
Output is correct |
70 |
Correct |
27 ms |
3664 KB |
Output is correct |
71 |
Correct |
53 ms |
4688 KB |
Output is correct |
72 |
Correct |
49 ms |
4424 KB |
Output is correct |
73 |
Correct |
62 ms |
5200 KB |
Output is correct |
74 |
Correct |
27 ms |
3664 KB |
Output is correct |
75 |
Correct |
31 ms |
3016 KB |
Output is correct |
76 |
Incorrect |
53 ms |
4424 KB |
Output isn't correct |
77 |
Halted |
0 ms |
0 KB |
- |