# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1083477 | lamlamlam | Bosses (BOI16_bosses) | C++17 | 510 ms | 848 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 int long long
#define endl '\n'
const int MN = 5005,inf = 1e18;
int n,k,u,ans = inf,h[MN];
vector<int> adj[MN];
int bfs(int x)
{
for(int i=1; i<=n; i++) h[i] = 0;
h[x] = 1;
queue<int> q;
q.push(x);
while(!q.empty()){
int u = q.front();
q.pop();
for(auto v:adj[u]){
if(h[v]!=0) continue;
h[v] = h[u] + 1;
q.push(v);
}
}
int res = 0;
for(int i=1; i<=n; i++) {
if(h[i]==0) return inf;
res += h[i];
}
return res;
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#define task "sus"
if(fopen(task".inp","r")){
freopen(task".inp","r",stdin);
freopen(task".out","w",stdout);
}
cin >> n;
for(int i=1; i<=n; i++){
cin >> k;
while(k--){
cin >> u;
adj[u].push_back(i);
}
}
for(int i=1; i<=n; i++) ans = min(ans,bfs(i));
cout << ans;
cerr << "\nTime: " << clock();
}
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... |