Submission #235458

#TimeUsernameProblemLanguageResultExecution timeMemory
235458anonymousBosses (BOI16_bosses)C++14
100 / 100
760 ms760 KiB
#include <iostream> #include <queue> #include <vector> #define MAXN 5005 using namespace std; int N, Ans=1<<30, Val, ki, dist[MAXN]; vector <int> adj[MAXN]; queue <int> Q; int main() { //freopen("bossin.txt","r",stdin); scanf("%d",&N); for (int i=1; i<=N; i++) { scanf("%d", &ki); for (int j=0; j<ki; j++) { int ai; scanf("%d",&ai); adj[ai].push_back(i); } } for (int i=1; i<=N; i++) { for (int j=1; j<=N; j++) { dist[j] = i == j ? 1 : 1<<30; } Val = 0; Q.push(i); int vis = 0; while (Q.size()) { int u = Q.front(); vis++; Q.pop(); Val += dist[u]; for (int v: adj[u]) { if (dist[v] > dist[u] + 1) { dist[v] = dist[u] + 1; Q.push(v); } } } if (vis == N) {Ans = min(Ans, Val);} } printf("%d",Ans); }

Compilation message (stderr)

bosses.cpp: In function 'int main()':
bosses.cpp:11:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&N);
     ~~~~~^~~~~~~~~
bosses.cpp:13:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &ki);
         ~~~~~^~~~~~~~~~~
bosses.cpp:16:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d",&ai);
             ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...