답안 #339599

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
339599 2020-12-25T17:02:21 Z TheYellowFlash Traffic (IOI10_traffic) C++17
0 / 100
22 ms 31596 KB
#include "traffic.h"
#include <bits/stdc++.h>
using namespace std;

#define ll int64_t
#define all(x) x.begin(), x.end()

const int mxN = 1e6+3;
vector<int> adj[mxN];
vector<ll> ans;
vector<ll> subtree(mxN, 0);
ll sum;

void dfs(int edge, int prev){
     for(auto& e: adj[edge]){
          if(e == prev) continue;
          dfs(e, edge);
          subtree[edge] += subtree[e];
          ans[edge] = max(ans[edge], subtree[e]);
     }
     ans[edge] = max(ans[edge], sum - ans[edge]);
}

int LocateCentre(int N, int pp[], int S[], int D[]) {
     ans.resize(N);
     for(int i = 0; i < N-1; ++i){
          adj[S[i]].push_back(D[i]);
          adj[D[i]].push_back(S[i]);
     }

     for(int i = 0; i < N; ++i){
          subtree[i] += pp[i];
          sum += pp[i];
     }

     dfs(0, 0);
     
     return min_element(all(ans)) - ans.begin();
}

// subtree[i] originally == node weight
// Increment it each time by weights of its subnodes
// Answer could be max(ans, sum(of all weights) - ans) 
# 결과 실행 시간 메모리 Grader output
1 Incorrect 22 ms 31596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 22 ms 31596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 22 ms 31596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 22 ms 31596 KB Output isn't correct
2 Halted 0 ms 0 KB -