Submission #1112170

#TimeUsernameProblemLanguageResultExecution timeMemory
1112170mariaclaraBosses (BOI16_bosses)C++17
100 / 100
404 ms724 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; const int MAXN = 5e3 + 5; #define all(x) x.begin(), x.end(); #define sz(x) (int)x.size() #define mk make_pair #define pb push_back #define fr first #define sc second int n, dist[MAXN]; vector<int> edges[MAXN]; int bfs(int x) { fill(dist+1, dist+1+n, n+1); queue<int> fila; fila.push(x); dist[x] = 1; int ans = 0, cnt = n; while(!fila.empty()) { int x = fila.front(); fila.pop(); ans += dist[x]; cnt--; for(auto viz : edges[x]) { if(dist[viz] > dist[x] + 1) { dist[viz] = dist[x] + 1; fila.push(viz); } } } if(cnt > 0) return n*n; return ans; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for(int i = 1, m, a; i <= n; i++) { cin >> m; while(m--) { cin >> a; edges[a].pb(i); } } int ans = n*n; for(int i = 1; i <= n; i++) { ans = min(ans, bfs(i)); } cout << ans << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...