이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")*/
#include <bits/stdc++.h>
using namespace std;
#define ll 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 answer=0;
queue<ll>q;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
used[j]=was[j]=1;
g[j].clear();ans[j]=0;
}
q.push(i);
used[i]=1;
while(q.size()>0)
{
ll x=q.front();
for(int it:v[x])
{
if(!used[it])
{
g[x].push_back(it);// dobei etot kod!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
q.push(it);
used[it]=1;
}
}
q.pop();
}
dfs(i);
cnt=0;
for(int j=1;j<=n;j++)
{
cnt+=ans[j];
if(ans[j]==0)ans[j]=1e9;
}
cout<<i<<" "<<answer<<"\n";
answer=max(answer,cnt);
}
cout<<answer;
}
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();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |