이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "towns.h"
using namespace std;
int a,b,c,d,e,i,j,ii,jj,zx,xc,fx[129][129],ind1,ind2,R,XOM,msh[129],zm[129],A;
int dista(int q, int w){
if(fx[q][w]!=0) return fx[q][w];
if(q==w) return 0;
fx[q][w]=fx[w][q]=getDistance(q-1,w-1);
return fx[q][w];
}
map <int, vector <int> > m;
bool check(int q, int w){
int qw=dista(ind1,q)+dista(ind1,w)-XOM*2;
if(qw==dista(q,w)){//sxvadasxvebia
return 0;
}else{//tolebia, lca qvemot aqvt ert qvexeshi arian
return 1;
}
}
int fnd(int q){
if(msh[q]==q) return q; else return msh[q]=fnd(msh[q]);
}
void mrg(int q, int w){
q=fnd(q);w=fnd(w);
if(q==w) return;
msh[w]=q;
zm[q]+=zm[w];
}
int hubDistance(int NN, int Ssub) {
/*int R = getDistance(0,1);
return R;*/
a=NN;m.clear();
for(i=0; i<=a+2; i++){
for(j=0; j<=a+2; j++){
fx[i][j]=0;
}
msh[i]=0;zm[i]=0;
}
ind1=2;
for(i=2; i<=a; i++){
if(dista(1,ind1)<dista(1,i)){
ind1=i;
}
}
ind2=1;
for(i=1; i<=a; i++){
if(i==ind1) continue;
if(dista(ind1,ind2)<dista(ind1,i)) ind2=i;
}
R=999999999;
A=dista(ind1,1)+dista(ind1,ind2)-dista(1,ind2);A/=2;
for(i=1; i<=a; i++){
zx=dista(ind1,i)+dista(1,i)-dista(ind1,1);zx/=2;
zx=dista(ind1,i)-zx;
if(zx>A) zx=A;
R=min(R,max(zx,dista(ind1,ind2)-zx));
m[zx].push_back(i);
}
/*cout<<ind1<<" "<<ind2<<" "<<R<<"\n";
for(auto taa:m){
vector <int> v=taa.second;
cout<<taa.first<<":\n";
for(auto x:v){
cout<<x<<" ";
}
cout<<"\n";
}*/
//return R;
int prv=0;
for(auto taa:m){
vector <int> v=taa.second;
int SZ=v.size();
//cout<<taa.first<<" started\n";
if(max(taa.first,dista(ind1,ind2)-taa.first)==R){
XOM=taa.first;
if(prv<=a/2&&SZ<=a/2&&a-SZ-prv<=a/2) return R;
if(prv<=a/2&&a-SZ-prv<=a/2){
vector <int> S,ise;
int alive=0;
S=v;
for(i=1; i<=a; i++){
msh[i]=i;zm[i]=1;
}
while(S.size()){
vector <int> nxt;
for(ii=1; ii<S.size(); ii+=2){
if(check(S[ii-1],S[ii])==1){
mrg(S[ii-1],S[ii]);
nxt.push_back(S[ii-1]);
}
}
if(S.size()%2==1) alive=S.back();
S=nxt;
}
if(alive==0) return R;
int mdeni=zm[fnd(alive)];
map <int, int> bo;
for(auto x:v){
if(fnd(x)==fnd(alive)) continue;
c=fnd(x);
if(bo[c]!=0) continue;
bo[c]=1;
if(check(c,alive)==1) mdeni+=zm[c];
}
if(mdeni<=a/2) return R;
}
}
prv+=SZ;
//cout<<taa.first<<" ended\n";
}
return -R;
}
컴파일 시 표준 에러 (stderr) 메시지
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:75:22: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
75 | int SZ=v.size();
| ~~~~~~^~
towns.cpp:90:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
90 | for(ii=1; ii<S.size(); ii+=2){
| ~~^~~~~~~~~
towns.cpp:29:29: warning: unused parameter 'Ssub' [-Wunused-parameter]
29 | int hubDistance(int NN, int Ssub) {
| ~~~~^~~~
# | 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... |