# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1015343 |
2024-07-06T08:54:53 Z |
우민규(#10889) |
Towns (IOI15_towns) |
C++14 |
|
16 ms |
1372 KB |
#include "towns.h"
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> qans;
int get_distance(int i, int j) {
if (i > j) swap(i, j);
if (qans[i][j] != -1) return qans[i][j];
return qans[i][j] = getDistance(i, j);
}
int hubDistance(int n, int sub) {
qans.assign(n, vector<int>(n, -1));
for (int i = 0; i < n; ++i) qans[i][i] = 0;
// get diameter of tree
int u = 1;
int uv = get_distance(0, u);
for (int i = 2; i < n; ++i) {
int di = get_distance(0, i);
if (di > uv) {
u = i;
uv = di;
}
}
int v = 0;
for (int i = 0; i < n; ++i) {
int di = get_distance(u, i);
if (di > uv) {
v = i;
uv = di;
}
}
// u - v w. length dd is diameter
int r = INT_MAX;
for (int i = 0; i < n; ++i) {
int iu = get_distance(i, u);
int iv = get_distance(i, v);
// 2*(i-h)
int ih = (iu + iv - uv) / 2;
int uh = iu - ih;
int vh = iv - ih;
r = min(r, max(uh, vh));
}
return r;
}
#ifndef EVAL
#include "grader.cpp"
#endif
Compilation message
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:14:28: warning: unused parameter 'sub' [-Wunused-parameter]
14 | int hubDistance(int n, int sub) {
| ~~~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
1116 KB |
Output is correct |
2 |
Correct |
7 ms |
860 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
9 ms |
860 KB |
Output is correct |
5 |
Correct |
10 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
1116 KB |
Output is correct |
2 |
Correct |
7 ms |
860 KB |
Output is correct |
3 |
Correct |
10 ms |
1060 KB |
Output is correct |
4 |
Correct |
16 ms |
856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
856 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
14 ms |
1372 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
860 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
860 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |