Submission #231732

# Submission time Handle Problem Language Result Execution time Memory
231732 2020-05-14T14:49:40 Z AlexLuchianov Traffic (IOI10_traffic) C++14
0 / 100
18 ms 23808 KB
#include "traffic.h"
#include <vector>
#include <iostream>

using namespace std;

int const nmax = 1000000;
int v[1 + nmax], sum[1 + nmax];
int far[1 + nmax];
vector<int> g[1 + nmax];

void dfs(int node, int parent){
  far[node] = parent;
  sum[node] = v[node];
  for(int h = 0; h < g[node].size(); h++){
    int to = g[node][h];
    if(to != parent) {
      dfs(to, node);
      sum[node] += sum[to];
    }
  }
}

int eval(int node){
  int result = sum[1] - sum[node];
  for(int h = 0; h < g[node].size(); h++){
    int to = g[node][h];
    if(to != far[node])
      result = max(result, sum[to]);
  }
  return result;
}

int LocateCentre(int n, int *p, int *s, int *d){
  for(int i = 0; i < n; i++){
    s[i]++;
    d[i]++;
    g[s[i]].push_back(d[i]);
    g[d[i]].push_back(s[i]);
  }
  for(int i = 1;i <= n; i++)
    v[i] = p[i - 1];
  dfs(1, 0);
  pair<int,int> sol(eval(1), 1);
  for(int i = 2;i <= n; i++){
    pair<int,int> candidate(eval(i), i);
    sol = min(sol, candidate);
  }
  return sol.second;
}

Compilation message

traffic.cpp: In function 'void dfs(int, int)':
traffic.cpp:15:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int h = 0; h < g[node].size(); h++){
                  ~~^~~~~~~~~~~~~~~~
traffic.cpp: In function 'int eval(int)':
traffic.cpp:26:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int h = 0; h < g[node].size(); h++){
                  ~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 23808 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 23808 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 23808 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 23808 KB Output isn't correct
2 Halted 0 ms 0 KB -