이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "towns.h"
#include <bits/stdc++.h>
using namespace std;
int hubDistance(int N, int sub) {
int root = 0;
vector<int>dist(N);
for (int i = 0;i<N;++i){
if (i == root)dist[i] = 0;
else dist[i] = getDistance(i,root);
}
for (int i = 0;i<N;++i){
if (dist[i] > dist[root]){
root = i;
}
}
for (int i = 0;i<N;++i){
if (i == root)dist[i] = 0;
else dist[i] = getDistance(i,root);
}
int root2 = root;
for (int i = 0;i<N;++i){
if (dist[i] > dist[root2])root2 = i;
}
int answer = dist[root2];
vector<int>dist2(N);
for (int i = 0;i<N;++i){
if (i == root2){
dist2[i] = 0;
}
else{
dist2[i] = getDistance(root2,i);
}
}
for (int i = 0;i<N;++i){
int x = (dist[i] + dist2[i] - dist[root2])/2;
answer = min(answer,max(dist[i] - x,dist2[i] - x));
}
bool ok = 0;
for (int i = 0;i<N;++i){
int x = (dist[i] + dist2[i] - dist[root2])/2;
if (answer == max(dist[i] - x,dist2[i] - x)){
int sub1 = 0,sub2 = 0,sub3 = 0,sub4 = 0;
for (int j = 0;j<N;++j){
if (dist[j] <= dist[i] - x){
sub1++;
}
else if (dist2[j]<=dist2[i] - x){
sub2++;
}
else if (getDistance(i,j) <=x)sub3++;
else sub4++;
}
if (sub4 > sub3){
for (int p = 0;p<3;++p){
if (sub4 > sub3)--sub4,++sub3;
}
}
if (max({sub3,sub1,sub2,sub4}) <=N/2){
ok = true;
return answer;
}
}
}
return -answer;
}
컴파일 시 표준 에러 (stderr) 메시지
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:38:7: warning: variable 'ok' set but not used [-Wunused-but-set-variable]
38 | bool ok = 0;
| ^~
towns.cpp:4:28: warning: unused parameter 'sub' [-Wunused-parameter]
4 | int hubDistance(int N, int sub) {
| ~~~~^~~
# | 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... |