Submission #735549

#TimeUsernameProblemLanguageResultExecution timeMemory
735549tigarBosses (BOI16_bosses)C++14
0 / 100
1 ms468 KiB
#include <bits/stdc++.h> using namespace std; int n; vector<int>graff[5050], tree[5050]; pair<int, int>d[5050]; bool check[5050], ch[5050]; int val[5050]; vector<pair<int, int> >ord; int reezz=0; void bfs(int v, int br) { if(check[v])return; check[v]=true; if(br!=0)tree[ord[br-1].second].push_back(v); for(int i=0; i<graff[v].size(); i++) { if(!check[graff[v][i]]){ord.push_back({graff[v][i], v}); /*tree[v].push_back(graff[v][i]);*/} } if(br==ord.size())return; bfs(ord[br].first, br+1); } int dfs(int v) { if(ch[v])return 0; ch[v]=true; int ans=1; for(int i=0; i<tree[v].size(); i++) { ans+=dfs(tree[v][i]); } reezz+=ans; return ans; } int main() { ios_base::sync_with_stdio(false); //cin.tie(0); cout.tie(0); cin>>n; for(int i=1; i<=n; i++) { int k; cin>>k; d[i].second=i; for(int j=0; j<k; j++) { int a; cin>>a; graff[a].push_back(i); d[a].first++; } } sort(d+1, d+n+1); bfs(d[n].second, 0); //for(int i=1; i<=n; i++){for(int j=0; j<tree[i].size(); j++)cout<<tree[i][j]<<" "; cout<<endl;} int k=dfs(d[n].second); cout<<reezz; return 0; } /*4 1 2 1 1 1 1 1 1 9*/

Compilation message (stderr)

bosses.cpp: In function 'void bfs(int, int)':
bosses.cpp:18:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     for(int i=0; i<graff[v].size(); i++)
      |                  ~^~~~~~~~~~~~~~~~
bosses.cpp:22:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     if(br==ord.size())return;
      |        ~~^~~~~~~~~~~~
bosses.cpp: In function 'int dfs(int)':
bosses.cpp:32:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |     for(int i=0; i<tree[v].size(); i++)
      |                  ~^~~~~~~~~~~~~~~
bosses.cpp: In function 'int main()':
bosses.cpp:60:9: warning: unused variable 'k' [-Wunused-variable]
   60 |     int k=dfs(d[n].second);
      |         ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...