# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1040006 | khanhtb | Bosses (BOI16_bosses) | C++14 | 395 ms | 5212 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 optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define pf push_front
#define vi vector<ll>
#define vii vector<vi>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define all(a) a.begin(), a.end()
#define fi first
#define se second
using namespace std;
const ll mod = 998244353;
const ll inf = 1e18;
const ll blocksz = 320;
const ll N = 2e5+8;
int n;
vector<int> g[N];
ll bfs(ll root){
queue<ll>qu; ll res = 0;
vector<ll>h(n+1,0); vector<bool>vis(n+1,false);
h[root] = 1; qu.push(root); vis[root] = true;
while(!qu.empty()){
ll u = qu.front(); qu.pop();
res += h[u];
for(int v : g[u]){
if(vis[v]) continue;
h[v] = h[u] + 1;
vis[v] = true;
qu.push(v);
}
}
bool flag = true;
for(ll i = 1;i <= n;++i) flag &= vis[i];
return (flag ? res : inf);
}
void solve(){
cin >> n;
for(int i = 1; i <= n; i++){
int k;cin >> k;
for(int j = 1; j <= k; j++){
int p;cin >> p;
g[p].pb(i);
}
}
ll ans = inf;
for(int i = 1; i <= n; i++){
ans = min(ans,bfs(i));
}
cout << ans;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if (fopen("test.inp", "r")) {
freopen("test.inp", "r", stdin);
freopen("test.out", "w", stdout);
}
int T = 1;
// cin >> T;
for (int i = 1; i <= T; i++) {
solve();
cout << '\n';
}
}
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... |