이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
// #include "traffic.h"
using namespace std;
typedef long long int ll;
vector<vector<int>> graph;
vector<ll> cost;
vector<bool> visited;
vector<ll> DP;
ll traffic (int city) {
if (DP[city] != -1) return DP[city];
DP[city] = cost[city];
visited[city] = true;
for (int road: graph[city]) {
if (!visited[road]) DP[city] += traffic(road);
}
return DP[city];
}
int LocateCentre(int N, int pp[], int S[], int D[]) {
graph.assign(N, vector<int>());
cost.clear();
DP.assign(N, -1);
for (int i = 0; i < N; i++) {
graph[S[i]].push_back(D[i]);
graph[D[i]].push_back(S[i]);
cost.push_back(pp[i]);
}
vector<pair<ll, int>> maximums (N);
visited.assign(N, false);
for (int city = 0; city < N; city++) {
if ((int)graph[city].size() > 1)
continue;
ll congestion = traffic(city);
congestion = 0;
for (auto road: graph[city]) {
congestion = max(congestion, traffic(road));
}
maximums[city].first = congestion;
maximums[city].second = city;
}
sort (maximums.begin(), maximums.end());
pair<ll, int> arenaCity = maximums[0];
return arenaCity.second;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |