Submission #757674

#TimeUsernameProblemLanguageResultExecution timeMemory
757674DavidAA007Bosses (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; ifstream fin("conexidad.in"); ofstream fout("conexidad.out"); const int mare=1e9; int T,n,m,k,x,y,c,i,j; int aux,start,maxx,summax,minn; int st,dr,mij,contor,suma,poz,dim; int dist[5005]; vector<int> G[5005]; queue<int> q; 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(i=1;i<=n;i++) { if(dist[i]==mare) { ok=0; break; } contor=contor+dist[i]; } 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...