제출 #554140

#제출 시각아이디문제언어결과실행 시간메모리
554140AlmaTraffic (IOI10_traffic)C++14
50 / 100
110 ms262144 KiB
#include <bits/stdc++.h> // #include "traffic.h" using namespace std; typedef long long int ll; vector<vector<ll>> graph; vector<ll> cost; vector<bool> visited; vector<vector<ll>> DP; void re_assign (int N, int idx) { visited.assign(N, 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 LocateCentre(int N, int pp[], int S[], int D[]) { graph.assign(N, vector<ll> ()); 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(pp[i]); } vector<pair<ll, int>> maximums (N); ll congestion = 0; for (int city = 0; city < N; city++) { ll maxCongestion = 0; re_assign(N, 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 = maximums[0]; return arenaCity.second; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...