Submission #1137077

#TimeUsernameProblemLanguageResultExecution timeMemory
1137077arijit_biswasTraffic (IOI10_traffic)C++20
0 / 100
0 ms324 KiB
#include "traffic.h" #include<bits/stdc++.h> using namespace std; vector<vector<int>> g; vector<int> subtreeSum; void dfs(int node, int par, int p[]) { subtreeSum[node] = p[node]; for (auto &v : g[node]) { if (v != par) { dfs(v, node, p); subtreeSum[node] += subtreeSum[v]; } } } bool check(int x, int n, int p[]) { int maxTraffic = 1e9; for (int i = 0; i < n; i++) { int temp = 0; for (auto &v : g[i]) { subtreeSum.assign(n, 0); dfs(v, i, p); // for (auto &x : subtreeSum) { // cout << x << " "; // } // cout << " -> " << subtreeSum[v] << endl; temp = max(temp, subtreeSum[v]); } maxTraffic = min(maxTraffic, temp); // cout << endl; } return maxTraffic <= x; } int LocateCentre(int n, int p[], int s[], int d[]) { g.resize(n); for (int i = 0; i < n - 1; i++) { g[s[i]].push_back(d[i]); g[d[i]].push_back(s[i]); } int low = 1, high = 1000, ans = high; while (low <= high) { int mid = low + (high - low) / 2; if (check(mid, n, p)) { ans = mid; high = mid - 1; } else { low = mid + 1; } } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...