Submission #532996

#TimeUsernameProblemLanguageResultExecution timeMemory
532996makanhuliaBosses (BOI16_bosses)C++17
0 / 100
1 ms460 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long int n; vector<int> adj[5005]; int dist[5005][5005]; bool vis[5005][5005]; int bfs(int x) { queue <int> q; q.push(x); int sum = 1; dist[x][x] = 1; int mx = 0; vis[x][x] = true; while(!q.empty()) { int cur = q.front(); q.pop(); for(int i = 0; i < adj[cur].size(); i++) { int next = adj[cur][i]; if (!vis[next][x]) { vis[next][x] = true; dist[next][x] = dist[cur][x] + 1; sum += dist[next][x]; mx = max(mx, dist[next][x]); q.push(next); } } } int ret = (n * (mx + 1)) - sum; return ret; } int main() { cin >> n; for(int i = 1; i <= n; i++) { int k; cin >> k; for(int j = 0; j < k; j++) { int next; cin >> next; adj[next].push_back(i); } } int mn = 1e9; for(int i = 1; i <= n; i++) { mn = min(mn, bfs(i)); } cout << mn << endl; }

Compilation message (stderr)

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