제출 #478474

#제출 시각아이디문제언어결과실행 시간메모리
478474ShinBosses (BOI16_bosses)C++14
100 / 100
701 ms5280 KiB
#include <bits/stdc++.h> #define fi first #define se second #define mp make_pair #define all(x) x.begin(), x.end() using namespace std; const int N = 2e5 + 7; const int MOD = 1e9 + 7; // 998244353; const int INF = 1e9 + 7; const long long INFLL = 1e18 + 7; template <class X, class Y> bool minimize(X &a, Y b) { if (a > b) return a = b, true; return false; } template <class X, class Y> bool maximize(X &a, Y b) { if (a < b) return a = b, true; return false; } int n; vector<int> adj[N]; void solve(void) { cin >> n; for (int i = 1; i <= n; i ++) { int k; cin >> k; while (k --) { int v; cin >> v; adj[v].push_back(i); } } long long res = INFLL; for (int root = 1; root <= n; root ++) { queue<int> q; q.push(root); vector<int> level(n + 1, 0); level[root] = 1; long long sum = 0; int cnt = 0; while (!q.empty()) { int u = q.front(); q.pop(); sum += level[u]; cnt ++; for (int v: adj[u]) if (level[v] == 0) { level[v] = level[u] + 1; q.push(v); } } if (cnt == n) minimize(res, sum); } cout << res; } int main(void) { cin.tie(0)->sync_with_stdio(0); int test = 1; // cin >> test; while (test --) { solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...