# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
994885 | Baytoro | Bosses (BOI16_bosses) | C++17 | 474 ms | 800 KiB |
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>
using namespace std;
#define fr first
#define sc second
#define pb push_back
#define int long long
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
void fopn(string name){
freopen((name+".in").c_str(),"r",stdin);
freopen((name+".out").c_str(),"w",stdout);
}
const int N=5005;
vector<int> g[N];
int cnt[N];
int n;
int bfs(int x){
vector<int> used(N);
queue<pair<int,int> > dq;
dq.push(make_pair(x,1));
int res=1;
used[x]=1;
while(!dq.empty()){
int k=dq.front().fr;
int d=dq.front().sc;
dq.pop();
for(auto it: g[k]){
if(!used[it]){
dq.push(make_pair(it,d+1));
res+=d+1;
used[it]=1;
}
}
}
for(int i=1;i<=n;i++)
if(!used[i])
return 1000000000;
return res;
}
void solve(){
cin>>n;
for(int i=1;i<=n;i++){
int k;cin>>k;
for(int j=0;j<k;j++){
int x;cin>>x;
g[x].pb(i);
}
}
int ans=1e9;
for(int i=1;i<=n;i++){
ans=min(ans,bfs(i));
}
cout<<ans<<endl;
}
signed main(){
//fopn("paint");
int t=1;//cin>>t;
while(t--) solve();
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |