This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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];
}
forn(i, 0, N - 2){
graph[S[i]].pb(D[i]);
graph[D[i]].pb(S[i]);
}
if(N > 1000){
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... |