제출 #368051

#제출 시각아이디문제언어결과실행 시간메모리
368051urd05Bosses (BOI16_bosses)C++14
100 / 100
748 ms748 KiB
#include <bits/stdc++.h> using namespace std; vector<int> adj[5000]; int dist[5000]; int main(void) { int n; scanf("%d",&n); for(int i=0;i<n;i++) { int k; scanf("%d",&k); for(int j=0;j<k;j++) { int x; scanf("%d",&x); x--; adj[x].push_back(i); } } int ret=1e9; for(int r=0;r<n;r++) { memset(dist,-1,sizeof(dist)); int sum=0; queue<int> q; dist[r]=0; q.push(r); while (!q.empty()) { int now=q.front(); q.pop(); for(int i=0;i<adj[now].size();i++) { int nt=adj[now][i]; if (dist[nt]==-1) { dist[nt]=dist[now]+1; q.push(nt); } } } for(int i=0;i<n;i++) { sum+=dist[i]; if (dist[i]==-1) { sum=1e9; } } ret=min(ret,sum); } printf("%d",n+ret); }

컴파일 시 표준 에러 (stderr) 메시지

bosses.cpp: In function 'int main()':
bosses.cpp:30:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |             for(int i=0;i<adj[now].size();i++) {
      |                         ~^~~~~~~~~~~~~~~~
bosses.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    9 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
bosses.cpp:12:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   12 |         scanf("%d",&k);
      |         ~~~~~^~~~~~~~~
bosses.cpp:15:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   15 |             scanf("%d",&x);
      |             ~~~~~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...