{"problem":{"name":"Endless Walk","description":{"content":"We have a simple directed graph $G$ with $N$ vertices and $M$ edges. The vertices are labeled as Vertex $1$, Vertex $2$, $\\ldots$, Vertex $N$. The $i$\\-th edge $(1\\leq i\\leq M)$ goes from Vertex $U_i$","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"abc245_f"},"statements":[{"statement_type":"Markdown","content":"We have a simple directed graph $G$ with $N$ vertices and $M$ edges. The vertices are labeled as Vertex $1$, Vertex $2$, $\\ldots$, Vertex $N$. The $i$\\-th edge $(1\\leq i\\leq M)$ goes from Vertex $U_i$ to Vertex $V_i$.\nTakahashi will start at a vertex and repeatedly travel on $G$ from one vertex to another along a directed edge. How many vertices of $G$ have the following condition: Takahashi can start at that vertex and continue traveling indefinitely by carefully choosing the path?\n\n## Constraints\n\n*   $1 \\leq N \\leq 2\\times 10^5$\n*   $0 \\leq M \\leq \\min(N(N-1), 2\\times 10^5)$\n*   $1 \\leq U_i,V_i\\leq N$\n*   $U_i\\neq V_i$\n*   $(U_i,V_i)\\neq (U_j,V_j)$ if $i\\neq j$.\n*   All values in input are integers.\n\n## Input\n\nInput is given from Standard Input in the following format:\n\n$N$ $M$\n$U_1$ $V_1$\n$U_2$ $V_2$\n$\\vdots$\n$U_M$ $V_M$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"abc245_f","tags":[],"sample_group":[["5 5\n1 2\n2 3\n3 4\n4 2\n4 5","4\n\nWhen starting at Vertex $2$, Takahashi can continue traveling indefinitely: $2$ $\\to$ $3$ $\\to$ $4$ $\\to$ $2$ $\\to$ $3$ $\\to$ $\\cdots$ The same goes when starting at Vertex $3$ or Vertex $4$. From Vertex $1$, he can first go to Vertex $2$ and then continue traveling indefinitely again.  \nOn the other hand, from Vertex $5$, he cannot move at all.\nThus, four vertices ―Vertex $1$, $2$, $3$, and $4$― satisfy the conditions, so $4$ should be printed."],["3 2\n1 2\n2 1","2\n\nNote that, in a simple directed graph, there may be two edges in opposite directions between the same pair of vertices. Additionally, $G$ may not be connected."]],"created_at":"2026-03-03 11:01:14"}}