题解
2023-06-04 13:21:48
发布于:上海
18阅读
0回复
0点赞
#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
using namespace std;
typedef long long ll;
const int inf = 5000005;
int n, m, i, j, a[1005], d[1005], ans, f[1005], k, vi[1005][1005], c[1005][1005], l;
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() {
ios::sync_with_stdio(false);
scanf("%d%d", &n, &m);
for (i = 1; i <= m; i++) {
scanf("%d", &a[0]);
for (j = 1; j <= a[0]; j++) scanf("%d", &a[j]);
l = 1;
for (j = a[1]; j < a[a[0]]; j++)
if (a[l] == j) l++;
else
for (k = 1; k <= a[0]; k++)
if (!vi[a[k]][j]) c[a[k]][++c[a[k]][0]] = j, vi[a[k]][j] = 1;
}
for (i = 1; i <= n; i++) ans = max(ans, dfs(i));
printf("%d", ans);
return 0;
}
这里空空如也
有帮助,赞一个