CarryQwQ @ 2022-07-15 21:21:07
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e3 + 10;
int te, tb, degree[MAXN], n, m, d[MAXN], ans = INT_MIN;
bool v[MAXN];
vector<int> G[MAXN];
void bfs() {
queue<int> q;
for (int i = 1; i <= n; i++) {
if (!degree[i]) {
q.push(i);
d[i] = 1;
}
}
while(q.size()) {
int x = q.front();
q.pop();
for (int i = 0; i < G[x].size(); i++) {
int y = G[x][i];
if (degree[y]) degree[y]--;
if (!degree[y]) {
q.push(y);
d[y] = d[x] + 1;
ans = max(ans, d[y]);
}
}
}
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i++) {
int t;
te = 0;
tb = 0;
scanf("%d", &t);
memset(v, false, sizeof(v));
for (int j = 1; j <= t; j++) {
int k;
scanf("%d", &k);
v[k] = true;
if (j == t)
te = k;
if (j == 1)
tb = k;
}
for (int l = tb; l <= te; l++) {
if (!v[l]) {
for (int ll = tb; ll <= te; ll++) {
if (v[ll]) {
G[ll].push_back(l);
degree[l]++;
}
}
}
}
}
bfs();
printf("%d", ans);
return 0;
}
by gzkeylucky @ 2022-08-01 22:10:41
会不会是建图的数组开小了