This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T>using ordered_set = tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;//find_by_order(ind);
//order_of_key()
#define int long long
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define yes "YES"
#define no "NO"
#define bigg INT_MAX
#define debug(x) cout<<(#x)<<" = " <<x<<endl;
#define all(x) x.begin(),x.end()
#define sz size()
#define nn '\n'
#define mms(x,y) memset(x,y,sizeof(x))
#define forr(i,j,n) for (int i=j; i<n; i++)
#define forn(i,j,n) for (int i=j; i>n; i--)
#define fi first
#define se second
#define la "LA"
#define cinn(x,y) for(int i=0; i<y; i++) cin>>x[i];
#define pii pair<int,int>
#define vi vector<int>
signed main()
{
// #ifndef LOCAL
// freopen("lifeguards.in","r",stdin);
// freopen("lifeguards.out","w", stdout);
// #endif
fast
int n;
cin>>n;
vi a[n+1];
forr(i,0,n)
{
int w;
cin>>w;
while(w--)
{
int x;
cin>>x;
a[x].pb(i+1);
}
}
int ans=bigg;
forr(i,1,n+1)
{
//big boss
int depth[n+1]={ };
queue <int> q;
q.push(i);
depth[i]=1;
while(!q.empty())
{
int x=q.front();
q.pop();
//out<<x<<endl;
for(auto y:a[x])
{
// cout<<yes<<y<<' '<<depth[y]<<endl;
if (depth[y]==0)
{
depth[y]=depth[x]+1;
q.push(y);
}
}
}
int cur=0;
forr(j,1,n+1)
{
//cout<<j<<' '<<depth[j]<<endl;
int t=depth[j];
if (t==0){ cur=bigg; break; }
cur+=t;
}
ans=min(ans,cur);
}
cout<<ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |