Submission #735568

#TimeUsernameProblemLanguageResultExecution timeMemory
735568tigarBosses (BOI16_bosses)C++14
0 / 100
1 ms564 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) { //cout<<v<<endl; if(check[v] and br!=ord.size()){bfs(ord[br].first, br+1); return;} else if(check[v] and br==ord.size())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); 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:16:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |     if(check[v] and br!=ord.size()){bfs(ord[br].first, br+1); return;}
      |                     ~~^~~~~~~~~~~~
bosses.cpp:17:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |     else if(check[v] and br==ord.size())return;
      |                          ~~^~~~~~~~~~~~
bosses.cpp:20:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     for(int i=0; i<graff[v].size(); i++)
      |                  ~^~~~~~~~~~~~~~~~
bosses.cpp:24: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]
   24 |     if(br==ord.size())return;
      |        ~~^~~~~~~~~~~~
bosses.cpp: In function 'int dfs(int)':
bosses.cpp:34:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |     for(int i=0; i<tree[v].size(); i++)
      |                  ~^~~~~~~~~~~~~~~
bosses.cpp: In function 'int main()':
bosses.cpp:61:9: warning: unused variable 'k' [-Wunused-variable]
   61 |     int k=dfs(d[n].second);
      |         ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...