Submission #421597

#TimeUsernameProblemLanguageResultExecution timeMemory
421597victoriadBosses (BOI16_bosses)C++14
0 / 100
1 ms204 KiB
#include <cmath> #include <cstdio> #include <iostream> #include <utility> #include <algorithm> #include <vector> #include <set> #include <queue> #include <map> using namespace std; void dfs(vector<vector<int> >&g,vector<int>&s,int n){ s[n]=1; for(int i:g[n]){ if(s[i]==0){ dfs(g,s,i); s[n]+=s[i]; } } } int main(){ ios::sync_with_stdio(false); cin.tie(NULL); int n,k,a; cin>>n; vector<vector<int> >em(n); for(int i=0;i<n;i++){ cin>>k; while(k--){ cin>>a; a--; em[a].push_back(i); } } vector<pair<int,int> >si(n); for(int i=0;i<n;i++){ si[i]=make_pair(em[i].size(),i); } sort(si.rbegin(),si.rend()); vector<vector<int> >sol(n); vector<bool>us(n,false); queue<int>cola; us[si[0].second]=true; cola.push(si[0].second); while(!cola.empty()){ int ac=cola.front(); cola.pop(); for(int i=0;i<em[ac].size();i++){ if(!us[em[ac][i]]){ us[em[ac][i]]=true; cola.push(em[ac][i]); sol[ac].push_back(em[ac][i]); } } } vector<int>sa(n,0); dfs(sol,sa,si[0].second); int ans=0; for(int i=0;i<n;i++){ ans+=sa[i]; } cout<<ans<<"\n"; }

Compilation message (stderr)

bosses.cpp: In function 'int main()':
bosses.cpp:49:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |   for(int i=0;i<em[ac].size();i++){
      |               ~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...