제출 #936306

#제출 시각아이디문제언어결과실행 시간메모리
936306wateronennBosses (BOI16_bosses)C++14
0 / 100
1 ms2660 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[i].push_back(m); } } ll sum = LLONG_MAX; for(int i=1;i<=n;i++){ bool visit[n+1]={0}; visit[i] = true; queue<pii> s; s.push({i,1}); ll nub = 0; int cnt = 1; //count node while(!s.empty()){ int u = s.front().f; int w = s.front().s; // cout<<u<<","<<w<<"* "; s.pop(); visit[u] = true; for(auto v:g[u]){ if(!visit[v]) { 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...