#include <iostream>
using namespace std;
struct node{
int src;
node *next;
};
struct Graph{
int vertex;
node **adj;
};
int main() {
int V, E;
cin >> V >> E; // number of vertices and edges
Graph *g = new Graph();
g->vertex = V;
g->adj = new node*[V];
for(int i=0; i<V; i++)
g->adj[i] = NULL;
for(int i=0; i<E; i++) {
int u, v;
cin >> u >> v; // edge from u to v (directed graph)
node *temp = new node();
temp->src = u;
temp->next = g->adj[v];
g->adj[v] = temp;
}
for(int v=0; v<V; v++) {
cout << "Edges ending at " << v << " come from : [ ";
node *temp = g->adj[v];
while(temp!=NULL) {
cout << temp->src <<" ";
temp = temp->next;
}
cout << "]" <<endl;
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKc3RydWN0IG5vZGV7CglpbnQgc3JjOwoJbm9kZSAqbmV4dDsKfTsKCnN0cnVjdCBHcmFwaHsKCWludCB2ZXJ0ZXg7Cglub2RlICoqYWRqOwp9OwoKaW50IG1haW4oKSB7CglpbnQgViwgRTsKCWNpbiA+PiBWID4+IEU7IC8vIG51bWJlciBvZiB2ZXJ0aWNlcyBhbmQgZWRnZXMKCQoJR3JhcGggKmcgPSBuZXcgR3JhcGgoKTsKCWctPnZlcnRleCA9IFY7CglnLT5hZGogPSBuZXcgbm9kZSpbVl07Cglmb3IoaW50IGk9MDsgaTxWOyBpKyspCgkJZy0+YWRqW2ldID0gTlVMTDsKCQoJZm9yKGludCBpPTA7IGk8RTsgaSsrKSB7CgkJaW50IHUsIHY7CgkJY2luID4+IHUgPj4gdjsgIC8vIGVkZ2UgZnJvbSB1IHRvIHYgKGRpcmVjdGVkIGdyYXBoKQoJCQoJCW5vZGUgKnRlbXAgPSBuZXcgbm9kZSgpOwoJCXRlbXAtPnNyYyA9IHU7CgkJdGVtcC0+bmV4dCA9IGctPmFkalt2XTsKCQlnLT5hZGpbdl0gPSB0ZW1wOwoJfQoJCglmb3IoaW50IHY9MDsgdjxWOyB2KyspIHsKCQljb3V0IDw8ICJFZGdlcyBlbmRpbmcgYXQgIiA8PCB2IDw8ICIgY29tZSBmcm9tIDogWyAiOwoJCW5vZGUgKnRlbXAgPSBnLT5hZGpbdl07CgkJd2hpbGUodGVtcCE9TlVMTCkgewoJCQljb3V0IDw8IHRlbXAtPnNyYyA8PCIgIjsKCQkJdGVtcCA9IHRlbXAtPm5leHQ7CgkJfQoJCWNvdXQgPDwgIl0iIDw8ZW5kbDsKCX0KCQoJcmV0dXJuIDA7Cn0=