Submission #74488

#TimeUsernameProblemLanguageResultExecution timeMemory
74488polyfishBosses (BOI16_bosses)C++14
100 / 100
744 ms1424 KiB
//Pantyhose + glasses = infinity #include <bits/stdc++.h> using namespace std; #define debug(x) cerr << #x << " = " << x << '\n'; #define BP() cerr << "OK!\n"; #define PR(A, n) {cerr << #A << " = "; for (int _=1; _<=n; ++_) cerr << A[_] << ' '; cerr << '\n';} #define PR0(A, n) {cerr << #A << " = "; for (int _=0; _<n; ++_) cerr << A[_] << ' '; cerr << '\n';} #define FILE_NAME "data" const int MAX_N = 5002; const int64_t INF = 1e18; int n, d[MAX_N]; vector<int> g[MAX_N]; void enter() { cin >> n; for (int i=1; i<=n; ++i) { int k; cin >> k; while (k--) { int u; cin >> u; g[u].push_back(i); } } } int64_t bfs(int st) { queue<int> qu; memset(d, 0, sizeof(d)); d[st] = 1; qu.push(st); int64_t res = 0; int cnt = 0; while (qu.size()) { int u = qu.front(); res += d[u]; ++cnt; qu.pop(); for (auto v : g[u]) { if (d[v]==0) { d[v] = d[u] + 1; qu.push(v); } } } return cnt!=n ? INF : res; } void solve() { int64_t res = INF; for (int u=1; u<=n; ++u) res = min(res, bfs(u)); cout << res; } int main() { #ifdef OFFLINE_JUDGE freopen(FILE_NAME".inp", "r", stdin); freopen(FILE_NAME".out", "w", stdout); #endif ios::sync_with_stdio(0); cin.tie(0); enter(); solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...