이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "towns.h"
#include <bits/stdc++.h>
#define FOR(i,p,k) for(int i=(p);i<=(k);++i)
#define REP(i,n) FOR(i,0,(n)-1)
#define fi first
#define se second
#define debug(a) cerr << #a << ": " << a << "\n";
using namespace std;
typedef pair<int, int> pii;
int hubDistance(int n, int sub){
int a = 0;
vector<int> od0(n, 0);
FOR(i, 1, n-1){
od0[i] = getDistance(0, i);
if(od0[i] > od0[a]) a = i;
}
int b = 0;
vector<int> oda(n, 0);
REP(i, n) if(i != a){
oda[i] = getDistance(a, i);
if(oda[i] > oda[b]) b = i;
}
int sred = oda[b];
vector<int> odb(n, 0);
REP(i, n) if(i != b) odb[i] = getDistance(b, i);
set<int> secik;
REP(i, n){
int t = (oda[i]+odb[i]-sred)>>1, odla = oda[i]-t;
secik.emplace(odla);
}
int wyn = sred+1, poz = -1;
for(int off : secik){
int maks = 0;
REP(i, n){
int t = (oda[i]+odb[i]-sred)>>1, odla = oda[i]-t;
maks = max(maks, t + abs(off-odla));
}
if(maks < wyn) wyn = maks, poz = off;
}
if(sub <= 2) return wyn;
if(sub == 4){
int lewo = 0, prawo = 0, ja = 0;
REP(i, n){
int t = (oda[i]+odb[i]-sred)>>1;
int odla = oda[i]-t;
if(odla < poz) ++lewo;
if(odla == poz) ++ja;
if(odla > poz) ++prawo;
}
bool zle = 0;
zle |= lewo > n/2;
zle |= prawo > n/2;
zle |= ja > n/2;// wiem to jest jedno poddrzewo
if(zle) wyn = -wyn;
return wyn;
}
return wyn;
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |