# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1108279 | cuctuyetaz | Bosses (BOI16_bosses) | C++14 | 403 ms | 14224 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 fi first
#define se second
#define endl '\n'
#define all(v) v.begin(), v.end()
#define GBIT(mask, i) (((mask) >> (i)) & 1)
#define BIT(i) (1ll << (i))
#define pb push_back
#define fu(i, l, r) for (int i = (int) (l); i <= (int)(r); i++)
#define fd(i, r, l) for (int i = (int) (r); i >= (int)(l); i--)
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef unsigned long long ull;
typedef double dl;
const int MAXN =5e5 + 55;
const ll MOD = 1e9 + 7;
const ll oo = 1ll * MOD * MOD;
int n;
vector <int> ke[MAXN];
void rf() {
cin >> n;
fu(i, 1, n) {
int k, u;
cin >> k;
while (k--) {
cin >> u;
ke[u].pb(i);
}
}
}
int dist[MAXN];
void solve() {
ll res = oo;
fu(i, 1, n) {
queue <int> p;
int cursize = 0;
fu(j, 1, n) dist[j] = 0;
dist[i] = 1;
p.push(i);
ll ans = 0;
while (p.size()) {
int u = p.front();
cursize++;
ans += dist[u];
p.pop();
for (int v : ke[u]) if (dist[v] == 0) {
dist[v] = dist[u] + 1;
p.push(v);
}
}
if (cursize == n) res = min(res, ans);
}
cout << res << endl;
}
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define task "xD"
if (fopen(task".inp", "r")) {
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
int ntest = 1;
// cin >> ntest;
fu(i, 1, ntest) {
rf();
solve();
}
cerr << "\nTime : " << 1.0 * clock() / CLOCKS_PER_SEC << " ms \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... |