Submission #368062

#TimeUsernameProblemLanguageResultExecution timeMemory
368062benedict0724Bosses (BOI16_bosses)C++17
100 / 100
1247 ms888 KiB
#include <bits/stdc++.h> using namespace std; vector<int> adj[5001]; queue<int> q; bool visited[5001]; int dp[5001], parent[5001]; int n; int bfs(int x){ for(int i=1;i<=n;i++){ visited[i] = false; dp[i] = 0; } visited[x] = true; vector<int> seq; q.push(x); while(!q.empty()){ int now = q.front(); q.pop(); for(int i : adj[now]){ if(!visited[i]){ visited[i] = true; parent[i] = now; q.push(i); } } seq.push_back(now); } if(seq.size() != n) return 1e9; int sum = 0; for(int i=n-1;i>=0;i--){ dp[seq[i]] += 1; dp[parent[seq[i]]] += dp[seq[i]]; sum += dp[seq[i]]; } return sum; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); cin >> n; for(int i=1;i<=n;i++){ int k; cin >> k; for(int j=1;j<=k;j++){ int e; cin >> e; adj[e].push_back(i); } } int ans = 1e9; for(int i=1;i<=n;i++){ ans = min(ans, bfs(i)); } cout << ans; }

Compilation message (stderr)

bosses.cpp: In function 'int bfs(int)':
bosses.cpp:31:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   31 |     if(seq.size() != n) return 1e9;
      |        ~~~~~~~~~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...