제출 #447321

#제출 시각아이디문제언어결과실행 시간메모리
447321phathnvBosses (BOI16_bosses)C++11
100 / 100
753 ms656 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<vector<int>> adj(n, vector<int>()); for (int i = 0; i < n; i++) { int k; cin >> k; while (k--) { int p; cin >> p; adj[--p].push_back(i); } } int res = 1e9; for (int r = 0; r < n; r++) { vector<int> d(n, -1); queue<int> qu; d[r] = 1; qu.push(r); while (!qu.empty()) { int u = qu.front(); qu.pop(); for (int v : adj[u]) if (d[v] == -1) { d[v] = d[u] + 1; qu.push(v); } } if (*min_element(d.begin(), d.end()) != -1) res = min(res, accumulate(d.begin(), d.end(), 0)); } cout << res; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...