제출 #726969

#제출 시각아이디문제언어결과실행 시간메모리
726969rahulvermaBosses (BOI16_bosses)Java
67 / 100
1547 ms18984 KiB
import java.io.*; import java.util.*; public class bosses { public static void main(String[] args) { Scanner s = new Scanner(System.in); int n = s.nextInt(); ArrayList<ArrayList<Integer>> graph = new ArrayList<ArrayList<Integer>>(); for(int i = 0; i < n; i++) graph.add(new ArrayList<Integer>()); for(int i = 0; i < n; i++) { int k = s.nextInt(); for(int j = 0; j < k; j++) { int v = s.nextInt() - 1; graph.get(v).add(i); } } long ans = Long.MAX_VALUE; for(int i = 1; i < n; i++) { long cur = 1; Queue<Integer> q = new LinkedList<>(); q.add(i); int[] dist = new int[n]; Arrays.fill(dist, 0); dist[i] = 1; while(!q.isEmpty()) { int node = q.poll(); for(int node2: graph.get(node)) { if(dist[node2] == 0) { cur += dist[node] + 1; dist[node2] = dist[node] + 1; q.add(node2); } } } boolean reached = true; for(int x: dist) if(x == 0) reached = false; if(reached) ans = Math.min(ans, cur); } System.out.println(ans); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...