chose to join chains in a single diagram in the accompanying way: the main chain is skipped; the 1-st vertex of the I-th chain is associated by an edge with the computer based intelligence th vertex of the (i−1)- th chain; the last (ci-th) vertex of the I-th chain is associated by an edge
Correct answer will be upvoted else downvoted. Computer science.
you chose to join chains in a single diagram in the accompanying way:
the main chain is skipped;
the 1-st vertex of the I-th chain is associated by an edge with the computer based intelligence th vertex of the (i−1)- th chain;
the last (ci-th) vertex of the I-th chain is associated by an edge with the bi-th vertex of the (i−1)- th chain.
Compute the length of the longest straightforward cycle in the subsequent diagram.
A basic cycle is a chain where the first and last vertices are associated also. If you travel along the basic cycle, every vertex of this cycle will be visited precisely once.
Input
The principal line contains a solitary integer t (1≤t≤1000) — the number of experiments.
The main line of each experiment contains the single integer n (2≤n≤105) — the number of chains you have.
The second line of each experiment contains n integers c1,c2,… ,cn (2≤ci≤109) — the number of vertices in the relating chains.
The third line of each experiment contains n integers a1,a2,… ,an (a1=−1; 1≤
The fourth line of each experiment contains n integers b1,b2,… ,bn (b1=−1; 1≤bi≤ci−1).
Both a1 and b1 are equivalent to −1, they aren't utilized in diagram building and given only for list consistency. It's reliable that the amount of n over all experiments doesn't surpass 105.
Output
For each experiment, print the length of the longest basic cycle.
Step by step
Solved in 4 steps with 1 images