제출 #30680

#제출 시각아이디문제언어결과실행 시간메모리
30680zoomswkBosses (BOI16_bosses)C++14
100 / 100
1036 ms2244 KiB
#include <stdio.h> #include <vector> #include <queue> using namespace std; vector<int> way[5005]; int par[5005], deg[5005]; int val[5005]; int main(){ int n; scanf("%d", &n); for(int i=1; i<=n; i++){ int k; scanf("%d", &k); while(k--){ int x; scanf("%d", &x); way[x].push_back(i); } } int res = 1e9; for(int root=1; root<=n; root++){ queue<int> q; q.push(root); for(int i=1; i<=n; i++) par[i] = 0, deg[i] = 0, val[i] = 1; par[root] = root; while(!q.empty()){ int pos = q.front(); q.pop(); for(int v : way[pos]) if(!par[v]){ q.push(v); par[v] = pos; deg[pos]++; } } int valid = 1; for(int i=1; i<=n; i++){ if(!par[i]){ valid = 0; break; } } if(!valid) continue; for(int i=1; i<=n; i++) if(deg[i] == 0) q.push(i); int cur = 0; while(!q.empty()){ int pos = q.front(); q.pop(); cur += val[pos]; val[par[pos]] += val[pos]; deg[par[pos]]--; if(deg[par[pos]] == 0) q.push(par[pos]); } if(cur < res) res = cur; } printf("%d", res); return 0; }

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

bosses.cpp: In function 'int main()':
bosses.cpp:12:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
                    ^
bosses.cpp:15:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &k);
                        ^
bosses.cpp:18:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &x);
                            ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...