#include <bits/stdc++.h>
using namespace std;
const int N=50000+7;
int n;
int k;
int sol;
vector<int> g[N];
set<pair<int,int>> s;
void del(int x)
{
for (auto &i : g[x])
{
vector<int> gnew_i;
for (auto &y : g[i])
{
if (y!=x)
gnew_i.push_back(y);
}
s.erase({(int) g[i].size(),i});
s.insert({(int) g[i].size()-1,i});
g[i]=gnew_i;
}
g[x].clear();
}
bool on[N];
int sum[N];
int cur;
void bkt(int node)
{
cur++;
for (auto &it : g[node])
sum[it]++;
on[node]=1;
if (cur>sol)
sol=cur;
int possible=0;
vector<int>lol;
for (auto &x : g[node])
{
if ((cur==1||(int)g[node].size()>(int)g[x].size())&&on[x]==0&&sum[x]==cur)
{
possible++;
}
}
if (cur+possible<=sol)
{
on[node]=0;
cur--;
for (auto &it : g[node])
sum[it]--;
return;
}
for (auto &x : g[node])
{
if ((cur==1||(int)g[node].size()>(int)g[x].size())&&on[x]==0&&sum[x]==cur)
{
bkt(x);
}
}
on[node]=0;
cur--;
for (auto &it : g[node])
sum[it]--;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin>>n>>k;
for (int i=0;i<n;i++)
{
int l;
cin>>l;
for (int j=1;j<=l;j++)
{
int x;
cin>>x;
g[i].push_back(x);
}
sort(g[i].begin(),g[i].end());
s.insert({(int)g[i].size(),i});
}
while (!s.empty())
{
auto it=*s.begin();
s.erase(it);
int node=it.second;
bkt(node);
del(node);
}
cout<<sol<<"\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1536 KB |
Output is correct |
2 |
Correct |
1 ms |
1536 KB |
Output is correct |
3 |
Correct |
7 ms |
1920 KB |
Output is correct |
4 |
Correct |
56 ms |
2048 KB |
Output is correct |
5 |
Correct |
57 ms |
2048 KB |
Output is correct |
6 |
Correct |
9 ms |
1920 KB |
Output is correct |
7 |
Correct |
9 ms |
1920 KB |
Output is correct |
8 |
Correct |
3 ms |
1792 KB |
Output is correct |
9 |
Correct |
1 ms |
1536 KB |
Output is correct |
10 |
Correct |
3 ms |
1792 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1536 KB |
Output is correct |
2 |
Correct |
1 ms |
1536 KB |
Output is correct |
3 |
Correct |
7 ms |
1920 KB |
Output is correct |
4 |
Correct |
56 ms |
2048 KB |
Output is correct |
5 |
Correct |
57 ms |
2048 KB |
Output is correct |
6 |
Correct |
9 ms |
1920 KB |
Output is correct |
7 |
Correct |
9 ms |
1920 KB |
Output is correct |
8 |
Correct |
3 ms |
1792 KB |
Output is correct |
9 |
Correct |
1 ms |
1536 KB |
Output is correct |
10 |
Correct |
3 ms |
1792 KB |
Output is correct |
11 |
Correct |
56 ms |
2048 KB |
Output is correct |
12 |
Correct |
57 ms |
2048 KB |
Output is correct |
13 |
Correct |
1 ms |
1536 KB |
Output is correct |
14 |
Correct |
62 ms |
2048 KB |
Output is correct |
15 |
Incorrect |
1 ms |
1536 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1792 KB |
Output is correct |
2 |
Correct |
1 ms |
1536 KB |
Output is correct |
3 |
Correct |
1 ms |
1536 KB |
Output is correct |
4 |
Incorrect |
1 ms |
1536 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1536 KB |
Output is correct |
2 |
Correct |
1 ms |
1536 KB |
Output is correct |
3 |
Correct |
7 ms |
1920 KB |
Output is correct |
4 |
Correct |
56 ms |
2048 KB |
Output is correct |
5 |
Correct |
57 ms |
2048 KB |
Output is correct |
6 |
Correct |
9 ms |
1920 KB |
Output is correct |
7 |
Correct |
9 ms |
1920 KB |
Output is correct |
8 |
Correct |
3 ms |
1792 KB |
Output is correct |
9 |
Correct |
1 ms |
1536 KB |
Output is correct |
10 |
Correct |
3 ms |
1792 KB |
Output is correct |
11 |
Correct |
56 ms |
2048 KB |
Output is correct |
12 |
Correct |
57 ms |
2048 KB |
Output is correct |
13 |
Correct |
1 ms |
1536 KB |
Output is correct |
14 |
Correct |
62 ms |
2048 KB |
Output is correct |
15 |
Incorrect |
1 ms |
1536 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1536 KB |
Output is correct |
2 |
Correct |
1 ms |
1536 KB |
Output is correct |
3 |
Correct |
7 ms |
1920 KB |
Output is correct |
4 |
Correct |
56 ms |
2048 KB |
Output is correct |
5 |
Correct |
57 ms |
2048 KB |
Output is correct |
6 |
Correct |
9 ms |
1920 KB |
Output is correct |
7 |
Correct |
9 ms |
1920 KB |
Output is correct |
8 |
Correct |
3 ms |
1792 KB |
Output is correct |
9 |
Correct |
1 ms |
1536 KB |
Output is correct |
10 |
Correct |
3 ms |
1792 KB |
Output is correct |
11 |
Correct |
56 ms |
2048 KB |
Output is correct |
12 |
Correct |
57 ms |
2048 KB |
Output is correct |
13 |
Correct |
1 ms |
1536 KB |
Output is correct |
14 |
Correct |
62 ms |
2048 KB |
Output is correct |
15 |
Incorrect |
1 ms |
1536 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |