EumenidesHe @ 2024-05-06 17:01:07
我的代码
#include<iostream>
#include<cstring>
#include<queue>
using namespace std;
bool tu[1010][1010];
bool v[1010];
int n, m, s;
int ans;
int vec[1010];
int ru[1010],chu[1010];
bool vis[1010];
struct Node {
int u=0, val=0;
};
queue<Node>q;
int main()
{
ios::sync_with_stdio(false);
cin >> n >> m;
for (int i = 0; i < m; i++)
{
cin >> s;
memset(vec, 0, 4040);
memset(v, 0, 4040);
for (int j = 0; j < s; j++)
{
cin >> vec[j];
vis[vec[j]] = 1;
v[vec[j]] = 1;
}
for (int j = 0; j < s; j++)
{
for (int k = vec[j] + 1; k < vec[s - 1]; k++)
{
if (!v[k])tu[vec[j]][k] = 1;
}
}
}
for (int i = 1; i <= n; i++)
{
for (int j = i + 1; j <= n; j++)
{
if (tu[i][j]) { ru[j]++; chu[i]++; }
}
}
for (int i = 1; i <= n; i++)
if (ru[i] == 0)
q.push({i,1});
while (!q.empty())
{
int u = q.front().u;
int val = q.front().val;
q.pop();
for (int i = u + 1; i <= n; i++)
{
if (tu[u][i]) {
ru[i]--;
if (ru[i] == 0)
q.push({ i,val + 1 });
}
}
ans = max(val, ans);
}
cout << ans;
}
第一个数据点的输入 10 4 4 1 3 5 6 3 3 5 6 3 1 5 9 5 4 5 6 7 9
求大佬解答