Doubly Increasing Path

All submissions for this problem are available.
### Read problems statements in [Hindi](http://www.codechef.com/download/translated/COOK105/hindi/DINCPATH.pdf), [Mandarin Chinese](http://www.codechef.com/download/translated/COOK105/mandarin/DINCPATH.pdf), [Russian](http://www.codechef.com/download/translated/COOK105/russian/DINCPATH.pdf), [Vietnamese](http://www.codechef.com/download/translated/COOK105/vietnamese/DINCPATH.pdf) and [Bengali](http://www.codechef.com/download/translated/COOK105/bengali/DINCPATH.pdf) as well. You are given an undirected graph with $N$ nodes (numbered $1$ through $N$) and $M$ edges. Each node has a value; let's denote the value of node $i$ by $A_i$. Note that the graph is not necessarily simple. A *doubly increasing path* is a directed path such that both the values of nodes and differences of values of nodes on this path are strictly increasing. Formally, it is a sequence of nodes $p_1, p_2, p_3, \ldots, p_k$ for some integer (the length of this path) $k \ge 1$ such that $0 \lt A_{p_2}  A_{p_1} \lt A_{p_3}  A_{p_2} \lt \ldots \lt A_{p_k}  A_{p_{k1}}$ and for each valid $i$, nodes $p_i$ and $p_{i1}$ are connected by an edge. You need to find the length of the longest doubly increasing path in the graph. ### Input  The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.  The first line of each test case contains two spaceseparated integers $N$ and $M$.  The second line contains $N$ spaceseparated integers $A_1, A_2, \ldots, A_N$.  Each of the following $M$ lines contains two spaceseparated integers $u$ and $v$ denoting that nodes $u$ and $v$ are connected by an edge. ### Output For each test case, print a single line containing one integer — the maximum length of a doubly increasing path. ### Constraints  $1 \le T \le 10$  $1 \le N \le 10^5$  $1 \le M \le 10^5$  $1 \le u, v \le N$  $A_i \le 10^{15}$ for each valid $i$ ### Example Input ``` 2 5 4 1 2 3 4 5 2 4 1 5 1 3 3 5 5 4 1 2 3 4 5 3 5 1 2 4 5 5 2 ``` ### Example Output ``` 2 3 ``` ### Explanation **Example case 1:** Any path with length $2$ from a smaller node to a larger one is doubly increasing. There is no doubly increasing path with length greater than $2$. **Example case 2:** The path $1 \rightarrow 2 \rightarrow 5$ is doubly increasing.Author:  mathecodician 
Editorial  https://discuss.codechef.com/problems/DINCPATH 
Tags  cookoff, directedacyclicgraph, easy, mathecodician, topologicalsort 
Date Added:  13042019 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, kotlin, PERL6, TEXT, SCM chicken, PYP3, CLOJ, R, COB, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 