Triunghiuri

Time limit: 2s Memory limit: 512MB Input: Output:

Statement

Ana and Bogdan each draw NN lattice points (with integer coordinates) in the xOyxOy plane. Ana's points are denoted P0,P1,…,PNβˆ’1P_0, P_1, \dots, P_{N-1}, and Bogdan's points are denoted Q0,Q1,…,QNβˆ’1Q_0, Q_1, \dots, Q_{N-1}.

Bogdan notices an interesting property: for every ii from 00 to Nβˆ’1N-1, his point QiQ_i is the centroid of the triangle formed by Ana's point PiP_i and two other points of his own, QaiQ_{a_i} and QbiQ_{b_i} (where ai,bi∈{0,1,…,Nβˆ’1}a_i, b_i \in \{0, 1, \dots, N-1\}).

In a moment of carelessness, Ana erases the points drawn by Bogdan. Now he must reconstruct them, knowing only the coordinates of the points PiP_i and the relations described above (the pairs of indices aia_i and bib_i).

Requirement

Given the points P0,P1,…,PNβˆ’1P_0, P_1, \dots, P_{N-1} and the pairs of indices (ai,bi)(a_i, b_i) for each i∈{0,…,Nβˆ’1}i \in \{0, \dots, N-1\}, determine the coordinates of the points Q0,Q1,…,QNβˆ’1Q_0, Q_1, \dots, Q_{N-1}.

Implementation Details

You must implement a single function:

std::vector<std::pair<long long, long long>> solve(
    int N,
    std::vector<std::pair<long long, long long>> p,
    std::vector<int> a, std::vector<int> b);

The solve function is called by the judge exactly once and receives as parameters:

  • NN: the number of points drawn by Ana;
  • pp: the coordinates of the NN points drawn by Ana (indexed from 00);
  • aa and bb: representing the pairs of indices for each property

and must return a sequence of pairs, given by the coordinates of the points Q0,Q1,…,Qnβˆ’1Q_0, Q_1, \dots, Q_{n-1}.

Constraints

  • 3≀N≀300Β 0003 \leq N \leq 300 \ 000
  • 0≀ai,bi<N0 \leq a_i, b_i < N, for 0≀i<N0 \leq i < N
  • aiβ‰ ia_i \neq i, biβ‰ ib_i \neq i, aiβ‰ bia_i \neq b_i for 0≀i<N0 \leq i < N
  • All unordered pairs {ai,bi}\{a_i, b_i\} are pairwise distinct
  • 0≀0 \leq coordinates of points PiP_i <7β‹…1018< \mathbf{7 \cdot 10^{18}}, for 0≀i<N0 \leq i < N
  • 0≀0 \leq coordinates of points QiQ_i <7β‹…1018< \mathbf{7 \cdot 10^{18}}, for 0≀i<N0 \leq i < N
  • It is guaranteed that the triangles from the properties are not degenerate
  • It can be proven that there exists a unique solution for determining the points QiQ_i
  • The sides QaiQbiQ_{a_i}Q_{b_i} (the bases of the NN triangles) together form a single continuous geometric figure.

A geometric figure is continuous if, for any two points QuQ_u and QvQ_v we choose, there exists a sequence of points Qp1,Qp2,…,QpkQ_{p_1}, Q_{p_2}, \ldots, Q_{p_k} satisfying the following properties:

  • p1=up_1=u, pk=vp_k=v;
  • For every 1≀j<k1 \le j < k, there exists an unordered pair {Qai,Qbi}\{Q_{a_i}, Q_{b_i}\} in the input that coincides with {Qpj,Qpj+1}\{Q_{p_j}, Q_{p_{j+1}}\}.
# Score Constraints
1 2 N=3N = 3
2 7 N≀300N \leq 300
3 14 N≀3Β 000N \leq 3 \ 000
4 12 0≀0 \leq coordinates PiP_i, QiQ_i <109< \mathbf{10^{9}}, for 0≀i<N0 \leq i < N
5 24 NN is odd, the sides QaiQbiQ_{a_i}Q_{b_i} form a polygon
6 22 Randomly generated input data
7 19 No additional restrictions.

Example 1

input

4
3 2
7 3
6 7
2 6
2 3
3 0
0 1

output

4 4
5 4
5 5
4 5

Explanation

For the first example, the drawing is shown in the image below.
Ana's points are denoted P0,P1,P2,P3P_0, P_1, P_2, P_3, and Bogdan's points are denoted Q0,Q1,Q2,Q3Q_0, Q_1, Q_2, Q_3.

Example 2

input

3
399999993 599999990
1 200000002
200000017 26
1 2
2 0
0 1

output

250000001 350000002
150000003 250000005
200000007 200000011

Log in or sign up to be able to send submissions!