(UPD: 2024-12-04 14:48 UTC) Judge is not working due to Cloudflare incident. (URL) We can do nothing about it, sorry. After the incident is resolved, we will grade all submissions.

Submission #341736

#TimeUsernameProblemLanguageResultExecution timeMemory
341736ProUGTraffic (IOI10_traffic)C++14
100 / 100
1344 ms174828 KiB
#include <bits/stdc++.h> using namespace std; vector<int> adj[1000000]; int population_cumulative[1000000]; int population[1000000]; int highest_traffic[1000000]; int calculate_population (int node, int parent) { int total_population = population[node]; for (auto child : adj[node]) { if (child != parent) { total_population += calculate_population(child, node); } } population_cumulative[node] = total_population; return total_population; } void dfs (int node, int parent, int overload) { int current_ans = overload; int children_population = 0; for (auto child : adj[node]) { if (child != parent) { children_population += population_cumulative[child]; current_ans = max(current_ans, population_cumulative[child]); } } highest_traffic[node] = current_ans; for (auto child : adj[node]) { if (child != parent) { dfs(child, node, overload + population[node] + children_population - population_cumulative[child]); } } } int LocateCentre (int n, int p[], int d[], int s[]) { int root = 0; for (int i = 0; i < n; i++) { population[i] = p[i]; } for (int i = 0; i < n-1; i++) { int a, b; a = d[i]; b = s[i]; adj[a].push_back(b); adj[b].push_back(a); } calculate_population(root, -1); dfs(root, -1, 0); int lowest_traffic = INT_MAX, lowest_index = 0; for (int i = 0; i < n; i++) { if (highest_traffic[i] < lowest_traffic) { lowest_traffic = highest_traffic[i]; lowest_index = i; } } return lowest_index; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...