제출 #954678

#제출 시각아이디문제언어결과실행 시간메모리
9546784QT0RBosses (BOI16_bosses)C++17
0 / 100
1 ms576 KiB
#include <bits/stdc++.h> using namespace std; int visited[5002]; vector<int> graph[5002]; int iter=0; queue<pair<int,int>> q; int bfs(int v){ visited[v]=iter; q.push({v,1}); int ans=0; while(q.size()){ auto [v,d]=q.front(); q.pop(); ans+=d; for (auto u : graph[v])if (visited[u]!=iter){ visited[u]=iter; q.push({u,d+1}); } } return ans; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n,k,v; cin >> n; for (int i = 1; i<=n; i++){ cin >> k; for (int j = 1; j<=k; j++){ cin >> v; graph[v].push_back(i); } } int mn=1e9; for (int i = 1; i<=n; i++){ iter++; mn=min(mn,bfs(i)); } cout << mn << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...