제출 #973892

#제출 시각아이디문제언어결과실행 시간메모리
973892KasymKBosses (BOI16_bosses)C++17
100 / 100
860 ms1264 KiB
#include "bits/stdc++.h" using namespace std; int n; const int N = 5e3 + 5; vector<int> adj[N]; vector<int> taze_adj[N]; int vis[N], node_sany[N]; void dfs(int x){ node_sany[x] = 1; for(auto to : taze_adj[x]){ dfs(to); node_sany[x] += node_sany[to]; } } int kok(int x){ for(int i = 1; i <= n; ++i){ vis[i] = 0; node_sany[i] = 0; taze_adj[i].clear(); } queue<int> q; q.push(x); vis[x] = 1; while(!q.empty()){ int id = q.front(); q.pop(); for(auto to : adj[id]) if(!vis[to]){ vis[to] = 1; taze_adj[id].push_back(to); q.push(to); } } for(int i = 1; i <= n; ++i) if(!vis[i]) return -1; // eger birini hem gormedik bolsam, onda yalnysh bolyar dfs(x); int ret = 0; for(int i = 1; i <= n; ++i) ret += node_sany[i]; return ret; } int main(){ scanf("%d", &n); for(int i = 1; i <= n; ++i){ int K; scanf("%d", &K); while(K--){ int A; scanf("%d", &A); adj[A].push_back(i); } } int ans = INT_MAX; for(int i = 1; i <= n; ++i){ int kk = kok(i); if(~kk) ans = min(ans, kk); } printf("%d\n", ans); return 0; }

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

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