#B3613. Directed Graph Outgoing Edges Listing

    ID: 11273 Type: Default 1000ms 256MiB

Directed Graph Outgoing Edges Listing

Directed Graph Outgoing Edges Listing

Given a directed graph \(G\) with \(n\) nodes and \(m\) edges. The nodes are numbered from 1 to \(n\). For each vertex \(u\) (where \(u = 1,2,\ldots,n\)), output all the nodes \(v\) such that there is a directed edge from \(u\) to \(v\). The output for each vertex should list the adjacent nodes in increasing order. The vertices must be processed sequentially from 1 through \(n\).

Formally, if an edge is denoted as \(u \to v\), then for each \(u = 1,2,\ldots,n\), let \(A_u\) be the list of vertices \(v\) with an edge \(u \to v\). You need to output the sorted list (in increasing order) for each \(A_u\). If a vertex has no outgoing edges, output an empty line.

inputFormat

The first line contains two integers \(n\) and \(m\) \((1 \leq n, m \leq 10^5)\), denoting the number of vertices and edges respectively. Each of the next \(m\) lines contains two integers \(u\) and \(v\) indicating there is a directed edge from vertex \(u\) to vertex \(v\).

outputFormat

Output \(n\) lines. The \(i\)-th line should contain the destination vertices of all edges outgoing from vertex \(i\), sorted in increasing order and separated by a single space. If vertex \(i\) has no outgoing edges, output an empty line.

sample

3 3
1 2
1 3
2 3
2 3

3

</p>