This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<typename T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#include "towns.h"
int maxind(VL& a) {
int ret;
ll mx = -1e18;
rep(i, a.size()) if (a[i] > mx) {
mx = a[i];
ret = i;
}
return ret;
}
int hubDistance(int N, int SUBTASK) {
int n = N;
VL dist0, distd1, distd2;
dist0 = distd1 = distd2 = VL(n);
rep(u, n) dist0[u] = getDistance(0, u);
int d1 = maxind(dist0);
rep(u, n) distd1[u] = getDistance(d1, u);
int d2 = maxind(distd1);
rep(u, n) distd2[u] = getDistance(d2, u);
ll ans = 1e18;
rep(u, n) {
ll d = (distd1[u] + distd2[u] - distd1[d2])/2;
setmin(ans, max(distd1[u]-d, distd2[u]-d));
}
return ans;
}
Compilation message (stderr)
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:59:9: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
59 | return ans;
| ^~~
towns.cpp:44:28: warning: unused parameter 'SUBTASK' [-Wunused-parameter]
44 | int hubDistance(int N, int SUBTASK) {
| ~~~~^~~~~~~
towns.cpp: In function 'int maxind(VL&)':
towns.cpp:41:12: warning: 'ret' may be used uninitialized in this function [-Wmaybe-uninitialized]
41 | return ret;
| ^~~
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:52:38: warning: 'ret' may be used uninitialized in this function [-Wmaybe-uninitialized]
52 | rep(u, n) distd2[u] = getDistance(d2, u);
| ~~~~~~~~~~~^~~~~~~
towns.cpp:50:38: warning: 'ret' may be used uninitialized in this function [-Wmaybe-uninitialized]
50 | rep(u, n) distd1[u] = getDistance(d1, u);
| ~~~~~~~~~~~^~~~~~~
# | 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... |