제출 #640118

#제출 시각아이디문제언어결과실행 시간메모리
640118dantBosses (BOI16_bosses)C++14
100 / 100
626 ms652 KiB
#include <bits/stdc++.h> using namespace std; const int MAX = 5005 ; int vis[MAX] ; long long cost = 0; vector< vector<int> >adj(MAX) ; int n , cnt = 0 ; void bfs(int src) { queue< pair<int , int> >q ; q.push({src , 1}) ; vis[src] = 1 ; while(!q.empty()) { pair<int , int>p = q.front() ; q.pop() ; cnt++ ; int node = p.first ; cost += (p.second * 1ll) ; for(auto &child : adj[node]) { if(vis[child] == 1) continue ; vis[child] = 1 ; q.push({child , p.second+1}) ; } } return ; } int main() { scanf("%d" , &n) ; for(int i = 1 ; i <= n ; ++i) { int m ; scanf("%d" , &m) ; while(m--) { int x ; scanf("%d" , &x) ; adj[x].push_back(i) ; } } long long ans = 1e18 ; for(int i = 1 ; i <= n ; ++i) { memset(vis , 0 , sizeof(vis)) ; cnt = 0 , cost = 0; bfs(i) ; if(cnt != n) continue; ans = min(ans , cost) ; } return printf("%lld" , ans) , 0 ; }

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

bosses.cpp: In function 'int main()':
bosses.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |     scanf("%d" , &n) ;
      |     ~~~~~^~~~~~~~~~~
bosses.cpp:42:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |         scanf("%d" , &m) ;
      |         ~~~~~^~~~~~~~~~~
bosses.cpp:46:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |             scanf("%d" , &x) ;
      |             ~~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...