제출 #306801

#제출 시각아이디문제언어결과실행 시간메모리
306801kaplanbarBosses (BOI16_bosses)C++14
100 / 100
744 ms2944 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; constexpr int N = 1e5+5; int n; vector<int> adj[N]; ll solve(int root) { vector<ll> d(n, 1e9); d[root] = 1; queue<int> q; q.push(root); while(!q.empty()) { int now = q.front(); q.pop(); for(int v : adj[now]) { if(d[v] > d[now] + 1) { d[v] = d[now] + 1; q.push(v); } } } ll ret = 0; for(int i = 0; i < n; i++) { ret += d[i]; } return ret; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; for(int i = 0; i < n; i++) { int k; cin >> k; for(int j = 0; j < k; j++) { int x; cin >> x; x--; adj[x].push_back(i); } } ll ans = 1e9; for(int i = 0; i < n; i++) { ans = min(ans, solve(i)); } assert(ans != 1e9); cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...