#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define mp make_pair
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n , k;
cin >> n >> k;
vector <vector <int> > v(n + 7);
int ans = k;
for(int i = 2; i <= n; i++)
{
int a;
cin >> a;
v[i].resize(a + 1);
for(int j = 1; j <= a; j++)
{
cin >> v[i][j];
}
}
ans = max(ans , (int)v[n].size() - 1);
v[1].resize(k + 1 , 0);
vector <int> dp(v[n].size() + 7 , 1);
for(int i = n - 1; i >= 1; i--)
{
int s = v[i].size() - 1 , s2 = v[i + 1].size() - 1;
vector <int> zapotrzebowanie(s + 1, 0);
for(int j = 1; j <= s2; j++)
{
zapotrzebowanie[v[i + 1][j]] += dp[j];
}
int curr = 0;
for(int j = 1; j <= s; j++)
{
zapotrzebowanie[j] = max((int)1 , zapotrzebowanie[j]);
curr += zapotrzebowanie[j];
}
ans = max(ans , curr);
dp = zapotrzebowanie;
}
cout << ans;
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | #include <bits/stdc++.h> using namespace std; #define pb push_back #define int long long #define mp make_pair signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n , k; cin >> n >> k; vector <vector <int> > v(n + 7); int ans = k; for(int i = 2; i <= n; i++) { int a; cin >> a; v[i].resize(a + 1); for(int j = 1; j <= a; j++) { cin >> v[i][j]; } } ans = max(ans , (int)v[n].size() - 1); v[1].resize(k + 1 , 0); vector <int> dp(v[n].size() + 7 , 1); for(int i = n - 1; i >= 1; i--) { int s = v[i].size() - 1 , s2 = v[i + 1].size() - 1; vector <int> zapotrzebowanie(s + 1, 0); for(int j = 1; j <= s2; j++) { zapotrzebowanie[v[i + 1][j]] += dp[j]; } int curr = 0; for(int j = 1; j <= s; j++) { zapotrzebowanie[j] = max((int)1 , zapotrzebowanie[j]); curr += zapotrzebowanie[j]; } ans = max(ans , curr); dp = zapotrzebowanie; } cout << ans; return 0; } |
English