제출 #363954

#제출 시각아이디문제언어결과실행 시간메모리
363954AnaMBosses (BOI16_bosses)C++14
100 / 100
839 ms748 KiB
#include<bits/stdc++.h> using namespace std; int n,x,sef,mini=-1,trenutniz,di[5005]; vector<int> grane[5005]; queue<int> q; void bfs(int trenutni) { int vi[5005]={0}; for(int h=1;h<=n;h++) di[h]=0; vi[trenutni]=1; q.push(trenutni); while(!(q.empty())) { trenutni=q.front(); q.pop(); for (int h=0;h<grane[trenutni].size();h++) { x=grane[trenutni][h]; if (vi[x]==1) continue; di[x]=di[trenutni]+1; vi[x]=1; q.push(x); } } } int main() { scanf("%d",&n); for (int i=1;i<=n;i++) { scanf("%d",&x); for (int h=1;h<=x;h++) { scanf("%d",&sef); grane[sef].push_back(i); } } for(int i=1;i<=n;i++) { bfs(i); trenutniz=n; for (int h=1;h<=n;h++) { trenutniz+=di[h]; if ((di[h]==0)&&(h!=i)) {trenutniz=-1; break;} } if (trenutniz==-1) continue; if (mini==-1) {mini=trenutniz; continue;} if (trenutniz<mini) mini=trenutniz; } printf("%d",mini); }

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

bosses.cpp: In function 'void bfs(int)':
bosses.cpp:18:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |   for (int h=0;h<grane[trenutni].size();h++)
      |                ~^~~~~~~~~~~~~~~~~~~~~~~
bosses.cpp: In function 'int main()':
bosses.cpp:30:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   30 |  scanf("%d",&n);
      |  ~~~~~^~~~~~~~~
bosses.cpp:33:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   33 |   scanf("%d",&x);
      |   ~~~~~^~~~~~~~~
bosses.cpp:36:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   36 |    scanf("%d",&sef);
      |    ~~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...