(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 #347931

#TimeUsernameProblemLanguageResultExecution timeMemory
347931training4usacoTraffic (IOI10_traffic)C++11
100 / 100
1171 ms174976 KiB
#include "traffic.h" #include <climits> #include <iostream> #include <vector> using namespace std; int n; vector<int> p; vector<vector<int>> adj; vector<int> traffic; vector<int> children; int numFans = 0; void dfs (int idx, int par) { for (int i = 0; i < adj[idx].size(); ++i) { if (adj[idx][i] == par) { continue; } dfs(adj[idx][i], idx); children[idx] += children[adj[idx][i]]; traffic[idx] = max(traffic[idx], children[adj[idx][i]]); } traffic[idx] = max(traffic[idx], numFans - children[idx] - p[idx]); children[idx] += p[idx]; } int LocateCentre (int ni, int pi[], int d[], int s[]) { n = ni; p = vector<int>(n); for(int i = 0; i < n; ++i) { p[i] = pi[i]; } adj = vector<vector<int>>(n); traffic = vector<int>(n); children = vector<int>(n); for (int i = 0; i < n; i++) { numFans += p[i]; } for (int i = 0; i < n - 1; i++) { adj[s[i]].push_back(d[i]); adj[d[i]].push_back(s[i]); } dfs(0, -1); int best = INT_MAX; int ans = -1; for (int i = 0; i < n; i++) { if (traffic[i] < best) { ans = i; best = traffic[i]; } } return ans; }

Compilation message (stderr)

traffic.cpp: In function 'void dfs(int, int)':
traffic.cpp:17:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |     for (int i = 0; i < adj[idx].size(); ++i) {
      |                     ~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...