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 "towns.h"
#include <bits/stdc++.h>
using namespace std;
const int maxn = 120;
const int maxm = 1e6+10;
const int inf = 0x3f3f3f3f;
int qs[maxn][maxn];
int sol[maxm];
vector<int> onh;
int query(int a, int b) {
if (a > b) swap(a, b);
if (qs[a][b] == -1) qs[a][b] = getDistance(a, b);
return qs[a][b];
}
int a, b;
int B;
bool subtree(int x, int y) {
//int xd = (query(a, x) + query())
}
int hubDistance(int n, int sub) {
memset(qs, -1, sizeof qs);
memset(sol, inf, sizeof sol);
for (int i = 0; i < n; i++)
qs[i][i] = 0;
a = 0, b = 0;
for (int i = 0; i < n; i++)
if (query(0, a) < query(0, i)) a = i;
for (int i = 0; i < n; i++)
if (query(a, b) < query(a, i)) b = i;
B = b; b = 0;
for (int i = 0; i < n; i++) {
int cd = (query(a, i) + query(b, i) - query(a, b)) / 2;
int ad = query(a, i) - cd;
int bd = query(a, B) - ad;
sol[ad] = max({cd, ad, bd});
}
int hu = 0;
for (int i = 0; i < maxm; i++)
if (sol[hu] > sol[i]) hu = i;
int lef = 0, rig = 0;
for (int i = 0; i < n; i++) {
int cd = (query(a, i) + query(b, i) - query(a, b)) / 2;
int ad = query(a, i) - cd;
int bd = query(a, b) - ad;
if (ad == hu) onh.push_back(i);
else if (ad < hu) lef++;
else rig++;
}
return sol[hu];
}
Compilation message (stderr)
towns.cpp: In function 'bool subtree(int, int)':
towns.cpp:23:1: warning: no return statement in function returning non-void [-Wreturn-type]
}
^
towns.cpp:21:18: warning: unused parameter 'x' [-Wunused-parameter]
bool subtree(int x, int y) {
^
towns.cpp:21:25: warning: unused parameter 'y' [-Wunused-parameter]
bool subtree(int x, int y) {
^
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:56:7: warning: unused variable 'bd' [-Wunused-variable]
int bd = query(a, b) - ad;
^~
towns.cpp:25:28: warning: unused parameter 'sub' [-Wunused-parameter]
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... |