Submission #851127

#TimeUsernameProblemLanguageResultExecution timeMemory
851127BenmathBosses (BOI16_bosses)C++14
67 / 100
1557 ms1184 KiB
/****************************************************************************** Online C++ Compiler. Code, Compile, Run and Debug C++ program online. Write your code in this editor and press "Run" button to compile and execute it. *******************************************************************************/ #include <bits/stdc++.h> using namespace std; int n; vector<int> v[5010]; int vis[5010]; int vis_dfs[5010]; int subtree[5010]; vector<int> adjl[5010]; int brojac = 0; void dfs (int s){ vis_dfs[s]++; subtree[s]++; for(int i = 0; i < adjl[s].size(); i++){ if(vis_dfs[adjl[s][i]] == 0){ dfs(adjl[s][i]); subtree[s] += subtree[adjl[s][i]]; } } brojac = brojac + subtree[s]; } int main() { cin >> n; for (int i = 1; i <= n; i++){ int x; cin >> x; for(int j = 0;j < x;j++){ int y; cin >> y; v[i].push_back(y); } } int ans = 1e9; for(int i = 1; i <= n; i++){ for(int j = 1; j <= n; j++){ vis[j] = 0; vis_dfs[j] = 0; subtree[j] = 0; adjl[j].clear(); } vis[i]++; brojac = 0; queue<int>q; q.push(i); while (!q.empty()){ int a = q.front(); q.pop(); vector<int>pronadeni; for (int j = 1; j <= n; j++){ if (vis[j] == 0){ for (int k = 0; k < v[j].size(); k++){ if(v[j][k] == a){ pronadeni.push_back(j); break; } } } } for (int j = 0; j < pronadeni.size(); j++){ adjl[a].push_back(pronadeni[j]); vis[pronadeni[j]]++; q.push(pronadeni[j]); } } int ne_valja = 0; for (int j = 1;j <= n; j++){ if(vis[j] == 0){ ne_valja++; } } if(ne_valja == 0){ dfs (i); ans = min(ans, brojac); } } cout << ans; }

Compilation message (stderr)

bosses.cpp: In function 'void dfs(int)':
bosses.cpp:23:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     for(int i = 0; i < adjl[s].size(); i++){
      |                    ~~^~~~~~~~~~~~~~~~
bosses.cpp: In function 'int main()':
bosses.cpp:63:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |                     for (int k = 0; k < v[j].size(); k++){
      |                                     ~~^~~~~~~~~~~~~
bosses.cpp:71:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |             for (int j = 0; j < pronadeni.size(); j++){
      |                             ~~^~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...