이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define f first
#define s second
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> pi;
//간선 연결후 tree dp해보자  
int sz[100005],num[100005],cnt;
ll anw,n;
map<pi,ll> mp;
vector<int> g[100005];
vector<pi> ar;
const ll mod=1e9;
 
ll dfs(ll a,ll p)
{
	ll ret=sz[a];
	for(int i=0;i<g[a].size();i++)
		if(g[a][i]!=p)
			ret+=dfs(g[a][i],a);	
	anw=(anw+ret*(n-ret))%mod;
	return ret;
}
 
void add(ll a,ll b)
{
	assert(a!=b);
   g[a].push_back(b),g[b].push_back(a);
}
 
void calc()
{
	sort(ar.begin(),ar.end());  //점 0부터. 
	for(int i=0;i<=n;i++)
		g[i].clear(),sz[i]=0;
	cnt=0,mp.clear();
	num[0]=++cnt,sz[cnt]=1;
	for(int i=1;i<ar.size();i++)
	{
		if(ar[i-1].s+1==ar[i].s) num[i]=cnt;
		else num[i]=++cnt;
		sz[cnt]++;
	}
	ll j=0,i=0;
	while(ar[j].f!=ar[0].f) j++;
	for(int j=0;j<n;j++)
	{
		while(j<n&&ar[i].f+1!=ar[j].f)
		{
			if(ar[i].f>=ar[j].f) j++;
			else i++;
		}
		while(j<n&&ar[i].f+1==ar[j].f&&ar[i].s!=ar[j].s)
		{
			if(ar[i].s>ar[j].s) j++;
			else i++;
		}
		if(num[i]!=num[j]&&!mp[{num[i],num[j]}])
			add(num[i],num[j]),mp[{num[i],num[j]}]++;
	}
	dfs(1,-1);
}
 
int DistanceSum (int N, int *x, int *y)
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	n=N;
	for(int i=0;i<n;i++)
		ar.push_back({x[i],y[i]});
	calc();
	for(int i=0;i<n;i++)
		swap(ar[i].f,ar[i].s);
	calc();
	return anw;
}
컴파일 시 표준 에러 (stderr) 메시지
city.cpp: In function 'll dfs(ll, ll)':
city.cpp:20:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<g[a].size();i++)
              ~^~~~~~~~~~~~
city.cpp: In function 'void calc()':
city.cpp:40:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=1;i<ar.size();i++)
              ~^~~~~~~~~~| # | 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... |