{"problem":{"name":"Longest Path","description":{"content":"There is a directed graph $G$ with $N$ vertices and $M$ edges. The vertices are numbered $1, 2, \\ldots, N$, and for each $i$ ($1 \\leq i \\leq M$), the $i$\\-th directed edge goes from Vertex $x_i$ to $y","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"dp_g"},"statements":[{"statement_type":"Markdown","content":"There is a directed graph $G$ with $N$ vertices and $M$ edges. The vertices are numbered $1, 2, \\ldots, N$, and for each $i$ ($1 \\leq i \\leq M$), the $i$\\-th directed edge goes from Vertex $x_i$ to $y_i$. $G$ **does not contain directed cycles**.\nFind the length of the longest directed path in $G$. Here, the length of a directed path is the number of edges in it.\n\n## Constraints\n\n*   All values in input are integers.\n*   $2 \\leq N \\leq 10^5$\n*   $1 \\leq M \\leq 10^5$\n*   $1 \\leq x_i, y_i \\leq N$\n*   All pairs $(x_i, y_i)$ are distinct.\n*   $G$ **does not contain directed cycles**.\n\n## Input\n\nInput is given from Standard Input in the following format:\n\n$N$ $M$\n$x_1$ $y_1$\n$x_2$ $y_2$\n$:$\n$x_M$ $y_M$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"dp_g","tags":[],"sample_group":[["4 5\n1 2\n1 3\n3 2\n2 4\n3 4","3\n\nThe red directed path in the following figure is the longest:\n![image](https://img.atcoder.jp/dp/longest_0_muffet.png)"],["6 3\n2 3\n4 5\n5 6","2\n\nThe red directed path in the following figure is the longest:\n![image](https://img.atcoder.jp/dp/longest_1_muffet.png)"],["5 8\n5 3\n2 3\n2 4\n5 2\n5 1\n1 4\n4 3\n1 3","3\n\nThe red directed path in the following figure is one of the longest:\n![image](https://img.atcoder.jp/dp/longest_2_muffet.png)"]],"created_at":"2026-03-03 11:01:14"}}