Submission #79887

#TimeUsernameProblemLanguageResultExecution timeMemory
79887Just_Solve_The_ProblemBosses (BOI16_bosses)C++11
100 / 100
672 ms1308 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; const int N = (int)5e3 + 7; const int inf = (int)1e9 + 7; int n; ll ans = 1e18; vector < int > gr[N]; int d[N]; long long solve(int v) { ll sum = n; queue < int > q; for (int i = 1; i <= n; i++) { d[i] = inf; } d[v] = 0; q.push(v); while (!q.empty()) { v = q.front(); q.pop(); for (int to : gr[v]) { if (d[to] == inf) { d[to] = d[v] + 1; q.push(to); } } } for (int i = 1; i <= n; i++) { sum += d[i]; if (d[i] == inf) { return inf; } } return sum; } main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { int k; scanf("%d", &k); for (int j = 0; j < k; j++) { int as; scanf("%d", &as); gr[as].push_back(i); } } for (int i = 1; i <= n; i++) { ans = min(ans, solve(i)); } cout << ans; }

Compilation message (stderr)

bosses.cpp:40:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
bosses.cpp: In function 'int main()':
bosses.cpp:41:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
bosses.cpp:44:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &k);
   ~~~~~^~~~~~~~~~
bosses.cpp:47:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d", &as);
    ~~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...