# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
388248 | cpp219 | Bosses (BOI16_bosses) | C++14 | 753 ms | 672 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.
#pragma GCC optimization "Ofast"
#pragma GCC optimization "unroll-loop"
#pragma GCC target ("avx2")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
using namespace std;
const ll N = 5000 + 6;
const ll lim = 3e5 + 6;
const ll inf = 1e16 + 7;
typedef pair<ll,ll> LL;
vector<ll> g[N];
ll n,k,x,d[N],was[N],ans = inf;
ll oper(ll root){
ll res = 1,cnt = 1;
memset(was,0,sizeof(was)); was[root] = 1;
queue<ll> q; d[root] = 1; q.push(root);
while(!q.empty()){
ll u = q.front(); q.pop();
for (auto i : g[u]){
if (!was[i]){
was[i] = 1; d[i] = d[u] + 1; res += d[i];
q.push(i); cnt++;
}
}
}
//cout<<cnt; exit(0);
if (cnt == n) return res;
return inf;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
#define task "test"
if (fopen(task".inp", "r")){
freopen(task".inp", "r", stdin);
//freopen(task".out", "w", stdout);
}
cin>>n;
for (ll i = 1;i <= n;i++){
cin>>k;
while(k--) cin>>x,g[x].push_back(i);
}
//cout<<oper(4); return 0;
for (ll i = 1;i <= n;i++) ans = min(ans,oper(i));
cout<<ans;
}
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... |