#include<bits/stdc++.h>
using namespace std;
int main(){
map<int , vector< pair<int, int > > > adjList; // Seems like torture xD
/***********Explanation************
* Abstract form of a map = map< key, value >
* Here key = int,
* Value = vector of pairs
* Key is actually a node(let's say N) of graph here and
* Value is the vector containing all the nodes which are
* connected to N directly.
* Why we need pair< d1, d2 > ?
* d2 = node connected to N directly.
* d1 = weight of edge between N and d2.
* For unweighted graph we can use only int instead of pair
* or we can keep value 0 for all edges if we use pair of
* int like shown below.
*************************************/
// Suppose we are given number of edges 'n' and all the edges in form of (u, v).
// So we can use a for loop to scan inputs.
int n;
cin >> n;
for(int i = 0 ; i < n ; i ++){
int u, v;
cin >> u >> v;
// If graph is undirected:
/* 1. */ adjList[u].push_back(make_pair(0, v));
/* 2. */ adjList[v].push_back(make_pair(0, u));
// If graph is directed from u to v
// Then no need to write 2nd statement.
}
// Print Adjacency List
for(map<int , vector< pair<int, int > > >::iterator it = adjList.begin() ; it != adjList.end() ; it++){
cout << it->first << " : ";
vector<pair<int, int> > neighbours = it->second;
for(int i = 0 ; i < neighbours.size() ; i++){
cout << "(" << neighbours[i].first << " " << neighbours[i].second << ")";
}
cout << endl;
}
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWFpbigpewogIG1hcDxpbnQgLCB2ZWN0b3I8IHBhaXI8aW50LCBpbnQgPiA+ID4gYWRqTGlzdDsgIC8vIFNlZW1zIGxpa2UgdG9ydHVyZSB4RAogIAogIC8qKioqKioqKioqKkV4cGxhbmF0aW9uKioqKioqKioqKioqCiAgKiBBYnN0cmFjdCBmb3JtIG9mIGEgbWFwID0gbWFwPCBrZXksIHZhbHVlID4KICAqIEhlcmUga2V5ID0gaW50LAogICogICAgICBWYWx1ZSA9IHZlY3RvciBvZiBwYWlycwogICogS2V5IGlzIGFjdHVhbGx5IGEgbm9kZShsZXQncyBzYXkgTikgb2YgZ3JhcGggaGVyZSBhbmQgCiAgKiBWYWx1Z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