제출 #936316

#제출 시각아이디문제언어결과실행 시간메모리
936316wateronennBosses (BOI16_bosses)C++14
100 / 100
396 ms3156 KiB
#include<bits/stdc++.h> #define pii pair<int,int> #define f first #define s second #define ll long long using namespace std; const int N = 1e5+9; vector<int> g[N]; int main(){ cin.tie(0)->sync_with_stdio(false); int n,m; cin>>n; for(int i=1;i<=n;i++){ int k; cin>>k; for(int j=1;j<=k;j++){ cin>>m; g[m].push_back(i); } } ll sum = LLONG_MAX; for(int i=1;i<=n;i++){ bool visit[n+1]={0}; memset(visit,0,sizeof(visit)); visit[i] = true; queue<pii> s; s.push({i,1}); ll nub = 1; int cnt = 1; //count node while(!s.empty()){ int u = s.front().f; int w = s.front().s; // cout<<u<<","<<w<<"* "; s.pop(); for(auto v:g[u]){ if(visit[v]) continue; visit[v] = true; cnt++; nub+=(w+1); s.push({v,w+1}); } } // cout<<nub<<" "<<cnt<<endl; if(cnt<n) continue; sum = min(sum,nub); } cout<<sum; return 0; } /* 4 1 4 3 1 3 4 2 1 2 1 3 4 1 2 0 1 4 0 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...