Submission #68897

#TimeUsernameProblemLanguageResultExecution timeMemory
68897MANcityBosses (BOI16_bosses)C++14
67 / 100
1572 ms1260 KiB
///GAGO_O #include<iostream> #include<cstdio> #include<fstream> #include<algorithm> #include<cmath> #include<map> #include<queue> #include<set> #include<stack> #include<string> #include<cstring> #include<vector> using namespace std; #define for1(i,n) for(int i=1;i<=(int)n;i++) #define for0(i,n) for(int i=0;i<=(int)n;i++) #define forn(i,n) for(int i=n;i>=1;i--) #define fo(i,x,y) for(int i=x;i<=(int)y;i++) #define fr(i,x,y) for(int i=x;i>=(int)y;i--) #define pb push_back #define mp make_pair #define LL long long const LL Mod=1000*1000*1000+7; int n; int used[5002]; vector<vector<int> > g(5002); vector<vector<int> > G(5002); int ANS=0; int dfs(int v) { if(G[v].size()==0) { ANS+=1; return 1; } int S=0; for0(j,G[v].size()-1) { int to=G[v][j]; S+=dfs(to); } ANS+=(S+1); return (S+1); } int bfs(int x) { ANS=0; for1(i,n) used[i]=0; for1(i,n) G[i].clear(); int X=x; queue<int> q; q.push(x); used[x]=1; while(!q.empty()) { int x=q.front(); for0(j,g[x].size()-1) { int to=g[x][j]; if(used[to]==0) { used[to]=1; G[x].push_back(to); q.push(to); } } q.pop(); } for1(i,n) if(used[i]==0) return (100000000); dfs(X); return ANS; } int main() { cin>>n; for1(i,n) { int k; cin>>k; for1(j,k) { int x; cin>>x; g[x].push_back(i); } } int ans=100000000; for1(i,n) ans=min(ans,bfs(i)); cout<<ans<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...