Submission #381143

#TimeUsernameProblemLanguageResultExecution timeMemory
381143vijayTriumphal arch (POI13_luk)Java
0 / 100
2060 ms75412 KiB
import java.io.*; import java.util.*; public class luk { static int N; static int[] dayCount; static ArrayList<Integer>[] adj; public static void main(String[] args) throws IOException, FileNotFoundException { Scanner in = new Scanner(System.in); // PrintWriter out = new PrintWriter("luk.out"); N = in.nextInt(); dayCount = new int[N]; adj = new ArrayList[N]; for(int i = 0; i < N; i++){ adj[i] = new ArrayList<>(); } for(int i = 0; i < N - 1; i++){ int a = in.nextInt() - 1; int b = in.nextInt() - 1; adj[a].add(b); adj[b].add(a); } recurse(0, 0, -1); // System.out.println(Arrays.toString(dayCount)); // System.out.println(works(2)); int a = 0; int b = N - 1; while(a != b){ int mid = (a + b)/2; if(works(mid)){ b = mid; } else { a = mid + 1; } } System.out.println(a); } static boolean works(int count){ int[] at = new int[count]; int pos = 0; for(int dayPos = 1; dayPos < N; dayPos++){ for(int city = 0; city < dayCount[dayPos]; city++){ if(at[pos] >= dayPos){ return false; } at[pos]++; pos++; pos%=count; } } return true; } static void recurse(int position, int day, int prev){ dayCount[day]++; for(int ap: adj[position]){ if(ap != prev){ recurse(ap, day + 1, position); } } } }

Compilation message (stderr)

Note: luk.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...