이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "traffic.h"
#include <bits/stdc++.h>
#define forn(i, a, b) for(int i = int(a); i <= int(b); ++i)
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int lim = 1e6;
vi graph[lim];
int pesos[lim];
bool visitados[lim];
ll mayor = LLONG_MAX, res = 0;
ll precalculo[lim];
ll trafico(int u){
ll suma = 0;
for(int v : graph[u]){
if(!visitados[v]){
visitados[v] = 1;
suma += trafico(v);
}
}
return suma + (ll) pesos[u];
}
int LocateCentre(int N, int pp[], int S[], int D[]) {
forn(i, 0, N - 1){
pesos[i] = pp[i];
}
bool bandera = 1;
forn(i, 0, N - 2){
if(S[i] != i || D[i] != i + 1){
bandera = 0;
}
graph[S[i]].pb(D[i]);
graph[D[i]].pb(S[i]);
}
if(bandera){
precalculo[0] = (ll) pesos[0];
forn(i, 1, N - 1){
precalculo[i] = precalculo[i - 1] + (ll) pesos[i];
}
mayor = precalculo[N - 1] - precalculo[0];
res = 0;
if(precalculo[N - 2] <= mayor){
mayor = precalculo[N - 2];
res = N - 1;
}
forn(i, 1, N - 2){
if(precalculo[i - 1] + precalculo[N - 1] - precalculo[i] <= mayor){
res = i;
mayor = precalculo[i - 1] + precalculo[N - 1] - precalculo[i];
}
}
}
else{
ll aux;
forn(i, 0, N - 1){
forn(j, 0, N - 1){
visitados[j] = 0;
}
visitados[i] = 1;
aux = LLONG_MIN;
for(int j : graph[i]){
visitados[j] = 1;
ll var = trafico(j);
aux = max(aux, var);
}
if(mayor >= aux){
mayor = aux;
res = i;
}
}
}
return res;
}
# | 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... |