0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-24 16:48:49 +00:00
OI-codes/Luogu/P1983/P1983.cpp

47 lines
1.0 KiB
C++
Raw Normal View History

2020-11-05 07:59:54 +00:00
#include <bits/stdc++.h>
using namespace std;
2021-11-19 09:01:13 +00:00
int n, m, k, ans, l, a[1005], d[1005], c[1005][1005], f[1005];
2020-11-05 07:59:54 +00:00
bool v[1005][1005];
int dfs(int x) {
if (f[x]) {
return f[x];
}
for (int i = 1; i <= c[x][0]; i++) {
f[x] = max(f[x], dfs(c[x][i]));
}
return ++f[x];
}
int main() {
cin >> n >> m;
for (int i = 1; i <= m; i++) {
cin >> a[0];
for (int j = 1; j <= a[0]; j++) {
cin >> a[j];
}
l = 1;
for (int j = a[1]; j < a[a[0]]; j++) {
if (a[l] == j) {
l++;
2021-11-19 09:01:13 +00:00
} else {
2020-11-05 07:59:54 +00:00
for (int k = 1; k <= a[0]; k++) {
if (!v[a[k]][j]) {
int t = a[k];
c[t][0]++;
c[t][c[t][0]] = j;
2021-11-19 09:01:13 +00:00
v[t][j] = 1;
2020-11-05 07:59:54 +00:00
}
}
}
}
}
for (int i = 1; i <= n; i++) {
ans = max(ans, dfs(i));
}
cout << ans << endl;
return 0;
}