제출 #1030977

#제출 시각아이디문제언어결과실행 시간메모리
1030977dpsaveslivesBosses (BOI16_bosses)C++17
100 / 100
1036 ms1148 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 5010; vector<int> adj[MAXN]; vector<int> graph[MAXN],st; int N,ans,cnt; void dfs(int u, int p){ for(auto v : graph[u]){ if(v != p){ dfs(v,u); st[u] += st[v]; } } cnt += st[u]; } int bfs(int start){ queue<int> q; q.push(start); vector<int> dist(N+1,-1),par(N+1,-1); dist[start] = 0; int maxd = -1, ret = 0; while(!q.empty()){ int u = q.front(); q.pop(); for(auto v : adj[u]){ if(dist[v] == -1){ dist[v] = dist[u]+1; par[v] = u; q.push(v); } } } for(int i = 1;i<=N;++i) graph[i].clear(); for(int i = 1;i<=N;++i){ if(dist[i] == -1) return -1; graph[par[i]].push_back(i); } st = vector<int>(N+1,1); cnt = 0; dfs(start,0); return cnt; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N; for(int i = 1;i<=N;++i){ int k; cin >> k; for(int j = 0;j<k;++j){ int v; cin >> v; adj[v].push_back(i); } } int res = -1, root = -1; for(int i = 1;i<=N;++i){ int ret = bfs(i); if(ret == -1) continue; if(ret < res || res == -1){ res = ret; root = i; } } cout << res << "\n"; return 0; }

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

bosses.cpp: In function 'int bfs(int)':
bosses.cpp:19:9: warning: unused variable 'maxd' [-Wunused-variable]
   19 |     int maxd = -1, ret = 0;
      |         ^~~~
bosses.cpp:19:20: warning: unused variable 'ret' [-Wunused-variable]
   19 |     int maxd = -1, ret = 0;
      |                    ^~~
bosses.cpp: In function 'int main()':
bosses.cpp:50:19: warning: variable 'root' set but not used [-Wunused-but-set-variable]
   50 |     int res = -1, root = -1;
      |                   ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...