/*#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[2001];
vector<ll>g[2001];
bool used[2001];
ll ans[2001];
bool was[2001];
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);
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
park.cpp: In function 'void anomalous_solve()':
park.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 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |