Language: C++

#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

int gcd(int x,int y){
	if(y == 0)return x;
	return gcd(y,x%y);
}

vector<P> dir[1002][1002];
int f(int x,int y,int dx,int dy){
	int ret = 0;
	rep(i,dir[x][y].size()){
		P p = dir[x][y][i];
		int t = (p.fr-x)*dx + (p.sc-y)*dy;
		if(t > 0)ret |= 1;
		else if(t == 0)ret |= 3;
		else ret |= 2;
	}
	return ret;
}

ld cul_dist(ld x1,ld y1,ld x2,ld y2){
	return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
		static int n;
		static int xs,ys,xg,yg;
		static int x1[202],y1[202],x2[202],y2[202];
		static int cnt[1002][1002];
		static vector<P> G[1002][1002];
		static bool used[1002][1002];
		static ld dist[1002][1002];
		static P pre[1002][1002];
		priority_queue<pair<ld,P>,vector<pair<ld,P>>,greater<pair<ld,P>>> que;
int main(){
	while(1){
		scanf("%d",&n); if(n == 0)break;
		scanf("%d%d%d%d",&xs,&ys,&xg,&yg);
		rep(i,n){
			scanf("%d%d%d%d",&x1[i],&y1[i],&x2[i],&y2[i]);
		}
		
		rep(i,1002)rep(j,1002)cnt[i][j] = 0;
		rep(i,n){
			if(x1[i] > x2[i] || (x1[i] == x2[i] && y1[i] > y2[i])){
				swap(x1[i],x2[i]);
				swap(y1[i],y2[i]);
			}
			cnt[x1[i]][y1[i]] ++;
			cnt[x2[i]][y2[i]] ++;
		}
		
		rep(i,n){
			int dx = x2[i]-x1[i];
			int dy = y2[i]-y1[i];
			int g = gcd(abs(dx),abs(dy));
			dx /= g; dy /= g;
			int locx = x1[i]+dx , locy = y1[i]+dy;
			while(!(locx == x2[i] && locy == y2[i])){
				cnt[locx][locy] ++;
				locx += dx; locy += dy;
			}
		}
		
		rep(i,1002)rep(j,1002)dir[i][j].clear();
		rep(i,n){
			if(cnt[x1[i]][y1[i]] == 1){
				dir[x2[i]][y2[i]].pb(P(x1[i],y1[i]));
			}
			else if(cnt[x2[i]][y2[i]] == 1){
				dir[x1[i]][y1[i]].pb(P(x2[i],y2[i]));
			}
		}
		
		rep(i,1002)rep(j,1002)G[i][j].clear();
		rep(i,n){
			if(cnt[x1[i]][y1[i]] == 1 || cnt[x2[i]][y2[i]] == 1)continue;
			int dx = x2[i]-x1[i];
			int dy = y2[i]-y1[i];
			int g = gcd(abs(dx),abs(dy));
			dx /= g; dy /= g;
			int prex1 = -1 , prey1 = -1;
			int prex2 = -1 , prey2 = -1;
			int locx = x1[i] , locy = y1[i];
			while(locx <= x2[i] && !(dx == 0 && locy > y2[i])){
				if(cnt[locx][locy] >= 1){
					int t = f(locx,locy,dx,dy);
					if((t&1) == 0){
						if(prex1 != -1)G[prex1][prey1].pb(P(locx,locy));
						prex1 = locx; prey1 = locy;
					}
					else { prex1 = -1; prey1 = -1; }
					if((t&2) == 0){
						if(prex2 != -1)G[locx][locy].pb(P(prex2,prey2));
						prex2 = locx; prey2 = locy;
					}
					else { prex2 = -1; prey2 = -1; }
				}
				locx += dx; locy += dy;
			}
		}
		
		rep(i,1002)rep(j,1002){
			used[i][j] = false;
			dist[i][j] = (ld)INF;
			pre[i][j] = P ( -1 , -1 );
		}
		dist[xs][ys] = 0.0;
		que.push ( pair<ld,P> ( 0.0 , P ( xs,ys ) ) );
		while(!que.empty()){
			pair<ld,P> p = que.top(); que.pop();
			if(used[p.sc.fr][p.sc.sc])continue;
			used[p.sc.fr][p.sc.sc] = true;
			rep(i,G[p.sc.fr][p.sc.sc].size()){
				P to = G[p.sc.fr][p.sc.sc][i];
				if(dist[to.fr][to.sc] > dist[p.sc.fr][p.sc.sc] + cul_dist(p.sc.fr,p.sc.sc,to.fr,to.sc)){
					dist[to.fr][to.sc] = dist[p.sc.fr][p.sc.sc] + cul_dist(p.sc.fr,p.sc.sc,to.fr,to.sc);
					pre[to.fr][to.sc] = p.sc;
					que.push( pair<ld,P> ( dist[to.fr][to.sc] , to ) );
				}
			}
		}
		
		if(pre[xg][yg].fr == -1)cout << -1 << endl;
		else {
			vector<P> ans;
			P loc = P ( xg , yg );
			ans.pb(loc);
			while(loc != P(xs,ys)){
				loc = pre[loc.fr][loc.sc];
				ans.pb(loc);
			}
			rrep(i,ans.size()){
				if(!(cnt[ans[i].fr][ans[i].sc]-dir[ans[i].fr][ans[i].sc].size() == 1))printf("%d %d\n",ans[i].fr,ans[i].sc);
			}
			puts("0");
		}
	}
}

Compiler output:
a.cc:60:42: error: 'int y1 [202]' redeclared as different kind of entity
   60 |                 static int x1[202],y1[202],x2[202],y2[202];
      |                                          ^
In file included from /usr/include/features.h:523,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/os_defines.h:39,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/c++config.h:683,
                 from /usr/include/c++/14/bits/requires_hosted.h:31,
                 from /usr/include/c++/14/iostream:38,
                 from a.cc:1:
/usr/include/x86_64-linux-gnu/bits/mathcalls.h:257:1: note: previous declaration 'double y1(double)'
  257 | __MATHCALL (y1,, (_Mdouble_));
      | ^~~~~~~~~~
a.cc: In function 'int main()':
a.cc:72:54: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   72 |                         scanf("%d%d%d%d",&x1[i],&y1[i],&x2[i],&y2[i]);
      |                                                      ^
a.cc:77:68: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   77 |                         if(x1[i] > x2[i] || (x1[i] == x2[i] && y1[i] > y2[i])){
      |                                                                    ^
a.cc:77:70: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   77 |                         if(x1[i] > x2[i] || (x1[i] == x2[i] && y1[i] > y2[i])){
      |                                                                ~~~~~~^~~~~~~
a.cc:79:42: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   79 |                                 swap(y1[i],y2[i]);
      |                                          ^
a.cc:79:37: error: no matching function for call to 'swap(double (&)(double) noexcept, int&)'
   79 |                                 swap(y1[i],y2[i]);
      |                                 ~~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/14/exception:166,
                 from /usr/include/c++/14/ios:41,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41:
/usr/include/c++/14/bits/exception_ptr.h:229:5: note: candidate: 'void std::__exception_ptr::swap(exception_ptr&, exception_ptr&)'
  229 |     swap(exception_ptr& __lhs, exception_ptr& __rhs)
      |     ^~~~
/usr/include/c++/14/bits/exception_ptr.h:229:25: note:   no known conversion for argument 1 from 'double(double) noexcept' to 'std::__exception_ptr::exception_ptr&'
  229 |     swap(exception_ptr& __lhs, exception_ptr& __rhs)
      |          ~~~~~~~~~~~~~~~^~~~~
In file included from /usr/include/c++/14/bits/exception_ptr.h:41:
/usr/include/c++/14/bits/move.h:226:5: note: candidate: 'template<class _Tp> std::_Require<std::__not_<std::__is_tuple_like<_Tp> >, std::is_move_constructible<_Tp>, std::is_move_assignable<_Tp> > std::swap(_Tp&, _Tp&)'
  226 |     swap(_Tp& __a, _Tp& __b)
      |     ^~~~
/usr/include/c++/14/bits/move.h:226:5: note:   template argument deduction/substitution failed:
a.cc:79:37: note:   deduced conflicting types for parameter '_Tp' ('double(double) noexcept' and 'int')
   79 |                                 swap(y1[i],y2[i]);
      |                                 ~~~~^~~~~~~~~~~~~
/usr/include/c++/14/bits/move.h:250:5: note: candidate: 'template<class _Tp, long unsigned int _Nm> std::__enable_if_t<((bool)std::__is_swappable<_Tp>::value)> std::swap(_Tp (&)[_Nm], _Tp (&)[_Nm])'
  250 |     swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm])
      |     ^~~~
/usr/include/c++/14/bits/move.h:250:5: note:   template argument deduction/substitution failed:
a.cc:79:37: note:   mismatched types '_Tp [_Nm]' and 'double(double) noexcept'
   79 |                                 swap(y1[i],y2[i]);
      |                                 ~~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44:
/usr/include/c++/14/bits/stl_pair.h:1089:5: note: candidate: 'template<class _T1, class _T2> typename std::enable_if<std::__and_<std::__is_swappable<_T1>, std::__is_swappable<_T2> >::value>::type std::swap(pair<_T1, _T2>&, pair<_T1, _T2>&)'
 1089 |     swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y)
      |     ^~~~
/usr/include/c++/14/bits/stl_pair.h:1089:5: note:   template argument deduction/substitution failed:
a.cc:79:37: note:   mismatched types 'std::pair<_T1, _T2>' and 'double(double) noexcept'
   79 |                                 swap(y1[i],y2[i]);
      |                                 ~~~~^~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:1106:5: note: candidate: 'template<class _T1, class _T2> typename std::enable_if<(! std::__and_<std::__is_swappable<_T1>, std::__is_swappable<_T2> >::value)>::type std::swap(pair<_T1, _T2>&, pair<_T1, _T2>&)' (deleted)
 1106 |     swap(pair<_T1, _T2>&, pair<_T1, _T2>&) = delete;
      |     ^~~~
/usr/include/c++/14/bits/stl_pair.h:1106:5: note:   template argument deduction/substitution failed:
a.cc:79:37: note:   mismatched types 'std::pair<_T1, _T2>' and 'double(double) noexcept'
   79 |                                 swap(y1[i],y2[i]);
      |                                 ~~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:54:
/usr/include/c++/14/bits/basic_string.h:4039:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> void std::swap(__cxx11::basic_string<_CharT, _Traits, _Allocator>&, __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 4039 |     swap(basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~
/usr/include/c++/14/bits/basic_string.h:4039:5: note:   template argument deduction/substitution failed:
a.cc:79:37: note:   mismatched types 'std::__cxx11::basic_string<_CharT, _Traits, _Allocator>' and 'double(double) noexcept'
   79 |                                 swap(y1[i],y2[i]);
      |                                 ~~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/14/bits/memory_resource.h:47,
                 from /usr/include/c++/14/string:68:
/usr/include/c++/14/tuple:2805:5: note: candidate: 'template<class ... _Elements> typename std::enable_if<std::__and_<std::__is_swappable<_Elements>...>::value>::type std::swap(tuple<_UTypes ...>&, tuple<_UTypes ...>&)'
 2805 |     swap(tuple<_Elements...>& __x, tuple<_Elements...>& __y)
      |     ^~~~
/usr/include/c++/14/tuple:2805:5: note:   template argument deduction/substitution failed:
a.cc:79:37: note:   mismatched types 'std::tuple<_UTypes ...>' and 'double(double) noexcept'
   79 |                                 swap(y1[i],y2[i]);
      |                                 ~~~~^~~~~~~~~~~~~
/usr/include/c++/14/tuple:2823:5: note: candidate: 'template<class ... _Elements> typename std::enable_if<(! std::__and_<std::__is_swappable<_Elements>...>::value)>::type std::swap(tuple<_UTypes ...>&, tuple<_UTypes ...>&)' (deleted)
 2823 |     swap(tuple<_Elements...>&, tuple<_Elements...>&) = delete;
      |     ^~~~
/usr/include/c++/14/tuple:2823:5: note:   template argument deduction/substitution failed:
a.cc:79:37: note:   mismatched types 'std::tuple<_UTypes ...>' and 'double(double) noexcept'
   79 |                                 swap(y1[i],y2[i]);
      |                                 ~~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/14/vector:66,
                 from a.cc:3:
/usr/include/c++/14/bits/stl_vector.h:2122:5: note: candidate: 'template<class _Tp, class _Alloc> void std::swap(vector<_Tp, _Alloc>&, vector<_Tp, _Alloc>&)'
 2122 |     swap(vector<_Tp, _Alloc>& __x, vector<_Tp, _Alloc>& __y)
      |     ^~~~
/usr/include/c++/14/bits/stl_vector.h:2122:5: note:   template argument deduction/substitution failed:
a.cc:79:37: note:   mismatched types 'std::vector<_Tp, _Alloc>' and 'double(double) noexcept'
   79 |                                 swap(y1[i],y2[i]);
      |                                 ~~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/14/deque:66,
                 from /usr/include/c++/14/queue:62,
                 from a.cc:4:
/usr/include/c++/14/bits/stl_deque.h:2370:5: note: candidate: 'template<class _Tp, class _Alloc> void std::swap(deque<_Tp, _Alloc>&, deque<_Tp, _Alloc>&)'
 2370 |     swap(deque<_Tp,_Alloc>& __x, deque<_Tp,_Alloc>& __y)
      |     ^~~~
/usr/include/c++/14/bits/stl_deque.h:2370:5: note:   template argument deduction/substitution failed:
a.cc:79:37: note:   mismatched types 'std::deque<_Tp, _Alloc>' and 'double(double) noexcept'
   79 |                                 swap(y1[i],y2[i]);
      |                                 ~~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/14/queue:66:
/usr/include/c++/14/bits/stl_queue.h:445:5: note: candidate: 'template<class _Tp, class _Seq> typename std::enable_if<std::__is_swappable<_T2>::value>::type std::swap(queue<_Tp, _Seq>&, queue<_Tp, _Seq>&)'
  445 |     swap(queue<_Tp, _Seq>& __x, queue<_Tp, _Seq>& __y)
      |     ^~~~
/usr/include/c++/14/bits/stl_queue.h:445:5: note:   template argument deduction/substitution failed:
a.cc:79:37: note:   mismatched types 'std::queue<_Tp, _Seq>' and 'double(double) noexcept'
   79 |                                 swap(y1[i],y2[i]);
      |                                 ~~~~^~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:834:5: note: candidate: 'template<class _Tp, class _Sequence, class _Compare> typename std::enable_if<std::__and_<std::__is_swappable<_T2>, std::__is_swappable<_Compare> >::value>::type std::swap(priority_queue<_Tp, _Sequence, _Compare>&, priority_queue<_Tp, _Sequence, _Compare>&)'
  834 |     swap(priority_queue<_Tp, _Sequence, _Compare>& __x,
      |     ^~~~
/usr/include/c++/14/bits/stl_queue.h:834:5: note:   template argument deduction/substitution failed:
a.cc:79:37: note:   mismatched types 'std::priority_queue<_Tp, _Sequence, _Compare>' and 'double(double) noexcept'
   79 |                                 swap(y1[i],y2[i]);
      |                                 ~~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/14/map:62,
                 from a.cc:5:
/usr/include/c++/14/bits/stl_tree.h: