제출 #700996

#제출 시각아이디문제언어결과실행 시간메모리
700996KahouBosses (BOI16_bosses)C++14
100 / 100
657 ms680 KiB
#include<bits/stdc++.h> using namespace std; #define F first #define S second #define endl '\n' #define mk make_pair typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int inf = 1e9 + 50; const int N = 5e3 + 50; int n, d[N]; vector<int> adj[N]; void solve(){ cin >> n; for (int u = 1; u <= n; u++) { int k; cin >> k; for (int i = 1; i <= k; i++) { int v; cin >> v; adj[v].push_back(u); } } ll ans = inf; queue<int> q; for (int s = 1; s <= n; s++) { for (int u = 1; u <= n; u++) d[u] = inf; d[s] = 1; q.push(s); while (q.size()) { int u = q.front(); q.pop(); for (int v:adj[u]) { if (d[u]+1 < d[v]) { d[v] = d[u]+1; q.push(v); } } } ll sm = 0; for (int u = 1; u <= n; u++) { sm += d[u]; } ans = min(ans, sm); } cout << ans << endl; } int main() { ios::sync_with_stdio(0), cin.tie(0); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...