이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for(int i=0;i<n;++i)
#define pb push_back
#define all(x) x.begin(), x.end()
#define pi pair<int,int>
#define f first
#define s second
struct DSU {
	vector<int> p,sz;
	int tot;
	DSU(int n) {
		forn(i,n) p.pb(i), sz.pb(1);
		tot=n;
	}
	int get(int u) {
		return p[u]==u?u:get(p[u]);
	}
	void uni(int u, int v) {
		u=get(u), v=get(v);
		if (sz[u]<sz[v]) swap(u,v);
		sz[u]+=sz[v];
		p[v]=u;
		--tot;
	}
};
int p3(vector<int> x, vector<int> y) {
	int n=x.size();
	vector<int> u,v,a,b;
	map<pi,int> m;
	forn(i,n) m[{x[i],y[i]}]=i;
	DSU dsu(n);
	vector<pi> z={{-2,0},{2,0},{0,-2},{0,2}};
	forn(i,n) {
		int f=x[i], s=y[i];
		for(auto&x:z) {
			if (m.count({f+x.f,s+x.s})) {
				if (i<m[{f+x.f,s+x.s}]) {
					if (dsu.get(i)==dsu.get(m[{f+x.f,s+x.s}])) continue;
					dsu.uni(i,m[{f+x.f,s+x.s}]);
					u.pb(i), v.pb(m[{f+x.f,s+x.s}]);
				}
			}
		}
	}
	if (u.size()!=n-1) return 0;
	forn(i,n-1) {
		int x1=x[u[i]], y1=y[u[i]];
		int x2=x[v[i]], y2=y[v[i]];
		if (x1==x2) {
			if (x1==2) {
				a.pb(1);
				b.pb(max(y1,y2)-1);
			} else {
				a.pb(5);
				b.pb(max(y1,y2)-1);
			}
		} else {
			a.pb(3);
			b.pb(y1-1);
		}
	}
	build(u,v,a,b);
	return 1;
}
int construct_roads(vector<int> x, vector<int> y) {
	int mx=0; for(auto&v:x) mx=max(mx,v);
	if (mx<=4) return p3(x,y);
	int n=x.size();
	vector<int> u,v,a,b;
	map<pi,int> m;
	forn(i,n) m[{x[i],y[i]}]=i;
	DSU dsu(n);
	vector<pi> z={{-2,0},{2,0},{0,-2},{0,2}};
	forn(i,n) {
		int f=x[i], s=y[i];
		for(auto&x:z) {
			if (m.count({f+x.f,s+x.s})) {
				if (i<m[{f+x.f,s+x.s}]) {
					if (dsu.get(i)==dsu.get(m[{f+x.f,s+x.s}])) continue;
					dsu.uni(i,m[{f+x.f,s+x.s}]);
					u.pb(i), v.pb(m[{f+x.f,s+x.s}]);
				}
			}
		}
	}
	if (u.size()!=n-1) return 0;
	
	forn(i,n-1) {
		int x1=x[u[i]], y1=y[u[i]];
		int x2=x[v[i]], y2=y[v[i]];
		if (x1==x2) {
			if ((max(y1,y2)+x1)%4) {
				a.pb(x1+1);
				b.pb(max(y1,y2)-1);
			} else {
				a.pb(x1-1);
				b.pb(max(y1,y2)-1);
			}
		} else {
			if ((max(x1,x2)+y1)%4) {
				a.pb(max(x1,x2)-1);
				b.pb(y1-1);
			} else {
				a.pb(max(x1,x2)-1);
				b.pb(y1+1);
			}
		}
	}
	build(u,v,a,b);
	return 1;
}
컴파일 시 표준 에러 (stderr) 메시지
parks.cpp: In function 'int p3(std::vector<int>, std::vector<int>)':
parks.cpp:51:14: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   51 |  if (u.size()!=n-1) return 0;
      |      ~~~~~~~~^~~~~
parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:96:14: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   96 |  if (u.size()!=n-1) return 0;
      |      ~~~~~~~~^~~~~| # | 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... |