제출 #1083477

#제출 시각아이디문제언어결과실행 시간메모리
1083477lamlamlamBosses (BOI16_bosses)C++17
100 / 100
510 ms848 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define endl '\n' const int MN = 5005,inf = 1e18; int n,k,u,ans = inf,h[MN]; vector<int> adj[MN]; int bfs(int x) { for(int i=1; i<=n; i++) h[i] = 0; h[x] = 1; queue<int> q; q.push(x); while(!q.empty()){ int u = q.front(); q.pop(); for(auto v:adj[u]){ if(h[v]!=0) continue; h[v] = h[u] + 1; q.push(v); } } int res = 0; for(int i=1; i<=n; i++) { if(h[i]==0) return inf; res += h[i]; } return res; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #define task "sus" if(fopen(task".inp","r")){ freopen(task".inp","r",stdin); freopen(task".out","w",stdout); } cin >> n; for(int i=1; i<=n; i++){ cin >> k; while(k--){ cin >> u; adj[u].push_back(i); } } for(int i=1; i<=n; i++) ans = min(ans,bfs(i)); cout << ans; cerr << "\nTime: " << clock(); }

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

bosses.cpp: In function 'int main()':
bosses.cpp:37:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |         freopen(task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
bosses.cpp:38:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         freopen(task".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...