제출 #739130

#제출 시각아이디문제언어결과실행 시간메모리
739130josanneo22Bosses (BOI16_bosses)C++17
100 / 100
718 ms684 KiB
#include<bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define fi first #define se second int n; vector<vector<int>> adj(5005); int bfs(int root){ vector<int>d(n+1,0),vis(n+1,0); queue<int> q; q.push(root); vis[root]=1; d[root]=1; while(q.size()){ int u=q.front();q.pop(); for(auto&v:adj[u]){ if(vis[v]==0){ vis[v]=1; d[v]=d[u]+1; q.push(v); } } } for(int i=1;i<=n;i++){ if(vis[i]==0) return INT_MAX; } return accumulate(d.begin(),d.end(),0); } void solve(){ cin>>n; for(int i=1;i<=n;i++){ int k; cin>>k; for(int j=0;j<k;j++){ int a; cin>>a; adj[a].pb(i); } } int ans=INT_MAX; for(int i=1;i<=n;i++){ int f=bfs(i); ans=min(ans,f); } cout<<ans<<'\n'; } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...