/*#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
ll n,m,k,cnt;
vector<ll>v[5001];
vector<ll>g[5001];
bool used[5001];
ll ans[5001];
bool was[5001];
void dfs(ll x)
{
//cout<<x<<":";
ans[x]=1;
was[x]=1;
for(int it:g[x])
{
if(!was[it])
{
dfs(it);
ans[x]+=ans[it];
}
}
}
void anomalous_solve()
{
cin>>n;
ll x;
for(int i=1;i<=n;i++)
{
cin>>k;
for(int j=1;j<=k;j++)
{
cin>>x;
v[x].push_back(i);
}
}
ll mx=0,pos=-1;
for(int i=1;i<=n;i++)
{
//cout<<i<<":"<<v[i].size()<<"\n";
if(v[i].size()>mx)
{
mx=v[i].size();pos=i;
}
}
queue<ll>q;
q.push(pos);
used[pos]=1;
while(q.size()>0)
{
ll x=q.front();
for(int it:v[x])
{
if(!used[it])
{
g[x].push_back(it);
q.push(it);
used[it]=1;
}
}
q.pop();
}
dfs(pos);
for(int i=1;i<=n;i++)
{
cnt+=ans[i];
//cout<<ans[i]<<" ";
}
cout<<cnt;
}
int main()
{
// freopen("INPUT.txt","r",stdin);
// freopen("OUTPUT.txt","w",stdout);
ios_base::sync_with_stdio();
cin.tie(NULL);
cout.tie(NULL);
ll test=1;
//cin>>test;
for(int pos=1;pos<=test;pos++)
anomalous_solve();
}
Compilation message
bosses.cpp: In function 'void anomalous_solve()':
bosses.cpp:44:17: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
44 | if(v[i].size()>mx)
| ~~~~~~~~~~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
0 ms |
468 KB |
Output is correct |
3 |
Correct |
0 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
0 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
0 ms |
468 KB |
Output is correct |
3 |
Correct |
0 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
0 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
0 ms |
468 KB |
Output is correct |
3 |
Correct |
0 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
0 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |