uses
	testlib, SysUtils;

const
	maxn = 2000;
var
	i, j, n: longint;
	x, y, d, pd, a, b: array [1..maxn] of longint;
	u: array [1..maxn] of boolean;
	e: array [1..maxn, 1..maxn] of boolean;

procedure dfs(i: longint);
var
	j: longint;
begin
	u[i] := true;
	for j := 1 to n do begin
		if e[i][j] and not u[j] then
			dfs(j);
	end;
end;

function intersect(x1, y1, x2, y2, x3, y3, x4, y4: int64): boolean;
var
	v1, v2, v3, v4: int64;
begin
	intersect := false;
	v1 := (x2 - x1) * (y3 - y1) - (x3 - x1) * (y2 - y1);
	v2 := (x2 - x1) * (y4 - y1) - (x4 - x1) * (y2 - y1);
	if ((v1 <= 0) and (v2 <= 0)) or ((v1 >= 0) and (v2 >= 0)) then
		exit;
	v3 := (x4 - x3) * (y1 - y3) - (x1 - x3) * (y4 - y3);
	v4 := (x4 - x3) * (y2 - y3) - (x2 - x3) * (y4 - y3);
	if ((v3 <= 0) and (v3 <= 0)) or ((v4 >= 0) and (v4 >= 0)) then
		exit;
	writeln(x1, ' ', y1, ' ', x2, ' ', y2, ' ', x3, ' ', y3, ' ', x4, ' ', y4);
	writeln(v1, ' ', v2, ' ', v3, ' ', v4);
	intersect := true;
end;

begin
	n := inf.readlongint;
	for i := 1 to n do begin
		x[i] := inf.readlongint;
		y[i] := inf.readlongint;
		d[i] := inf.readlongint;
	end;

	for i := 1 to n - 1 do begin
		a[i] := ouf.readlongint;
		if a[i] = -1 then
			quit(_wa, '-1 unexpected');

		b[i] := ouf.readlongint;

		if (a[i] < 1) or (a[i] > n) or (b[i] < 1) or (b[i] > n) or (a[i] = b[i]) then
			quit(_wa, format('invalid edge: %d-%d', [a[i], b[i]]));
		if e[a[i]][b[i]] then
			quit(_wa, format('duplicate edge: %d-%d', [a[i], b[i]]));
		e[a[i]][b[i]] := true;
		e[b[i]][a[i]] := true;
		inc(pd[a[i]]);
		inc(pd[b[i]]);
	end;

	for i := 1 to n do begin
		if d[i] <> pd[i] then
			quit(_wa, format('wrong degree of city %d, expected: %d, found: %d', [i, d[i], pd[i]]));
	end;

	dfs(1);
	for i := 1 to n do begin
		if not u[i] then
			quit(_wa, format('city %d is not reachable from 1', [i]));
	end;

	for i := 1 to n - 1 do begin
		for j := i + 1 to n - 1 do begin
			if intersect(x[a[i]], y[a[i]], x[b[i]], y[b[i]], x[a[j]], y[a[j]], x[b[j]], y[b[j]]) then
				quit(_wa, format('edges %d-%d and %d-%d intersect', [a[i], b[i], a[j], b[j]]));
		end;
	end;

	quit(_ok, '');
end.