# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
341306 | AlexNeagu | Bosses (BOI16_bosses) | C++14 | 1219 ms | 876 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>
// #define int long long
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pi;
const int mod = 1e9 + 9;
const int N = 106 * 106;
const int nax = 1e6+6;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n;
ll ans = 2e18;
vector<int> possible_childs[5005];
ll root(int x) {
queue<int> Q;
Q.push(x);
vector<int> d(n + 1, 2e9), p(n + 1);
vector<ll> cnt(n + 1, 1LL);
vector<int> ord;
d[x] = 0;
while(Q.size()) {
int node = Q.front();
ord.pb(node);
Q.pop();
for(auto it : possible_childs[node]) {
if(d[node] + 1 < d[it]) {
d[it] = d[node] + 1;
Q.push(it);
p[it] = node;
}
}
}
for(int i = 1; i <= n; i++) if(d[i] == 2e9) return 2e18;
reverse(ord.begin(), ord.end());
ll sol = 0;
for(auto it : ord) {
sol += cnt[it];
if(it != x) {
cnt[p[it]] += cnt[it];
}
}
return sol;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for(int i = 1; i <= n; i++) {
int len;
cin >> len;
for(int j = 1; j <= len; j++) {
int x;
cin >> x;
possible_childs[x].push_back(i);
}
}
for(int i = 1; i <= n; i++) {
ans = min(ans, root(i));
}
cout << ans << '\n';
return 0;
}
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... |