제출 #757679

#제출 시각아이디문제언어결과실행 시간메모리
757679DavidAA007Bosses (BOI16_bosses)C++14
0 / 100
1 ms340 KiB
#include<bits/stdc++.h> #define mod 1000000007 #define bit(x,i)(((x)>>(i))&1) #define FAST ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); using namespace std; const long long int mare=1e9; long long int T,n,m,k,x,y,c,i,j; long long int aux,start,maxx,summax,minn,contor; long long int dist[5005]; vector<int> G[5005]; queue<int> q; long long int bfs(int nod) { for(i=1;i<=n;i++) { dist[i]=mare; } dist[nod]=1; q.push(nod); while(!q.empty()) { int j=q.front(); c=dist[j]; q.pop(); for(auto t:G[j]) { if(c+1<dist[t]) { dist[t]=c+1; q.push(t); } } } bool ok=1; for(j=1;j<=n;j++) { if(dist[j]==mare) { ok=0; break; } contor=contor+dist[j]; } if(!ok) return mare; return contor; } int main() { cin>>n; for(i=1;i<=n;i++) { cin>>k; for(j=1;j<=k;j++) { cin>>x; G[x].push_back(i); } } minn=mare; for(i=1;i<=n;i++) { minn=min(minn,bfs(i)); } cout<<minn; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...