This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
const int MAXN = 5e4 + 10;
deque<int> adj[MAXN];
void merge(deque<int>& v1, deque<int>& v2, deque<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(deque<int> pos) {
int mx = 0;
while (!pos.empty()) {
auto u = pos.front();
pos.pop_front();
deque<int> nxt;
merge(pos, adj[u], nxt);
mx = max(mx, 1 + best(nxt));
}
return mx;
}
int32_t main() {
int n, k;
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());
}
int ans = 0;
for (int i = 0; i < n; i++) {
ans = max(ans, best(adj[i]) + 1);
}
cout << ans << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |