# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
554130 | Alma | Traffic (IOI10_traffic) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 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<vector<ll>> DP;
void re_assign (int idx) {
visited.assign(5, false);
visited[idx] = true;
}
ll traffic (int prevCity, int city) {
if (DP[prevCity][city] != -1) return DP[prevCity][city];
DP[prevCity][city] = cost[city];
visited[city] = true;
for (int road: graph[city]) {
if (!visited[road]) DP[prevCity][city] += traffic(city, road);
}
return DP[prevCity][city];
}
int LocateCenter (int N, int pp[], int S[], int D[]) {
graph.assign(N, vector<int> ());
cost.clear();
DP.assign(N, vector<ll> (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(P[i]);
}
vector<pair<ll, int>> maximums (N);
ll congestion = 0;
for (int city = 0; city < N; city++) {
ll maxCongestion = -1;
re_assign(city);
for (int road: graph[city]) {
congestion = traffic (city, road);
maxCongestion = max(maxCongestion, congestion);
}
maximums[city].first = maxCongestion;
maximums[city].second = city;
}
sort (maximums.begin(), maximums.end());
pair<ll, int> arenaCity = *min_element(maximums.begin(), maximums.end());
return arenaCity.second;
}