제출 #39798

#제출 시각아이디문제언어결과실행 시간메모리
39798PajarajaBosses (BOI16_bosses)C++14
100 / 100
825 ms2296 KiB
#include <bits/stdc++.h> using namespace std; vector<int> g[5007]; bool vi[5007]; int dist[5007],n; long long bfs(int s) { queue<int> bfsq; bfsq.push(s); fill(vi,vi+5007,false); fill(dist,dist+5007,-1); vi[s]=true; dist[s]=0; while(!bfsq.empty()) { int u=bfsq.front(); for(int i=0;i<g[u].size();i++) if(!vi[g[u][i]]) { vi[g[u][i]]=true; dist[g[u][i]]=dist[u]+1; bfsq.push(g[u][i]); } bfsq.pop(); } long long sum=n; for(int i=1;i<=n;i++) { sum+=dist[i]; if(dist[i]==-1) return 1000000000000000000LL; } return sum; } int main() { scanf("%d",&n); for(int i=1;i<=n;i++) { int t,z; scanf("%d",&t); for(int j=0;j<t;j++) { scanf("%d",&z); g[z].push_back(i); } } long long sol=1000000000000000000LL; for(int i=1;i<=n;i++) sol=fmin(sol,bfs(i)); printf("%d",sol); }

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

bosses.cpp: In function 'long long int bfs(int)':
bosses.cpp:17:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<g[u].size();i++) if(!vi[g[u][i]])
                ^
bosses.cpp: In function 'int main()':
bosses.cpp:48:17: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
  printf("%d",sol);
                 ^
bosses.cpp:35:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
                ^
bosses.cpp:39:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&t);
                 ^
bosses.cpp:42:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d",&z);
                  ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...