이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "towns.h"
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int maxn = 1e2 + 20;
int h[2][maxn] , d[maxn] , p[maxn];
vector<int> ver[maxn];
int root(int v)
{
return p[v] < 0? v : p[v] = root(p[v]);
}
void merge(int a , int b)
{
a = root(a) , b = root(b);
if(a == b)
return;
p[a] += p[b];
p[b] = a;
}
int hubDistance(int n, int sub)
{
memset(h , 0 , sizeof h);
for(int i = 1; i < n; i++)
h[0][i] = getDistance(0 , i);
int a = max_element(h[0] , h[0] + n) - h[0];
memset(h[0] , 0 , sizeof h[0]);
for(int i = 0; i < n; i++)
if(i != a)
h[0][i] = getDistance(a , i);
int b = max_element(h[0] , h[0] + n) - h[0];
for(int i = 0; i < n; i++)
if(i != b)
h[1][i] = getDistance(b , i);
vector<int> val;
int ans = 1e9;
for(int i = 0; i < n; i++)
{
int k = (h[0][i] - h[1][i] + h[0][b]) / 2;
val.pb(k);
d[i] = h[0][i] - k;
ans = min(ans , max(k , h[0][b] - k));
}
sort(val.begin() , val.end());
val.resize(unique(val.begin() , val.end()) - val.begin());
int m = val.size();
for(int i = 0; i < m; i++)
ver[i].clear();
for(int i = 0; i < n; i++)
{
int k = (h[0][i] - h[1][i] + h[0][b]) / 2;
k = lower_bound(val.begin() , val.end() , k) - val.begin();
ver[k].pb(i);
}
bool has = 0;
for(int i = 0; i < m; i++)
if(max(val[i] , h[0][b] - val[i]) == ans)
{
if(n - (int)ver[i].size() > n / 2)
continue;
memset(p , -1 , sizeof p);
for(auto v : ver[i])
for(auto u : ver[i])
if(make_pair(d[v] , v) > make_pair(d[u] , u) && getDistance(v , u) != d[v] + d[u])
merge(v , u);
bool f = 1;
for(auto v : ver[i])
if(p[v] < 0 && -p[v] > n / 2)
f = 0;
has |= f;
}
if(!has)
ans = -ans;
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:36:39: warning: conversion to 'int' from 'long int' may alter its value [-Wconversion]
int a = max_element(h[0] , h[0] + n) - h[0];
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
towns.cpp:43:39: warning: conversion to 'int' from 'long int' may alter its value [-Wconversion]
int b = max_element(h[0] , h[0] + n) - h[0];
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
towns.cpp:61:18: warning: conversion to 'int' from 'std::vector<int>::size_type {aka long unsigned int}' may alter its value [-Wconversion]
int m = val.size();
~~~~~~~~^~
towns.cpp:68:48: warning: conversion to 'int' from '__gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type {aka long int}' may alter its value [-Wconversion]
k = lower_bound(val.begin() , val.end() , k) - val.begin();
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
towns.cpp:30: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... |