#include <vector>
#include <iostream>
#include <sstream>
#include <string>
#include <fstream>
#include <unordered_set>
#include <vector>
#include <set>
using namespace std;
int main()
{
int node1 = -1;
int node2 = -1;
string nodesText;
int nodesAmount = -1;
int edgeAmount = -1;
vector<vector<pair<string, int>>> graph;
cout << "Enter the nodes amount" << endl;
cin >> nodesAmount;
cout << "Enter the edge amount" << endl;
cin >> edgeAmount;
graph.resize(nodesAmount);
int counter = 0;
vector<string> edges;
edges.resize(edgeAmount);
set<int> nodes;
while (counter != edgeAmount)
{
cout << "Enter the nodes. Format:node 1 node 2" << endl;
cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
getline(cin, nodesText, '\n');
node1 = std::stoi(nodesText.substr(0, ' '));
node1 -= 1;
auto pos = nodesText.find(' ');
node2 = stoi(nodesText.substr(pos));
node2 -= 1;
nodes.insert(node1);
nodes.insert(node2);
cout << "Enter edge character" << endl;
cin >> edges[counter];
graph[node1].emplace_back(make_pair(edges[counter], node2));
graph[node2].emplace_back(make_pair(edges[counter], node1));
++counter;
}
cout << endl;
vector<int> nodesOutput;
for (auto itr : nodes)
{
nodesOutput.push_back(itr);
}
int counter2 = 0;
while (edges.size() > counter2)
{
cout << edges[counter2] << " " << nodesOutput[counter2]+1 << " " << nodesOutput[counter2+1]+1 << endl;
++counter2;
}
for (int i = 0; i < nodesAmount; i++)
{
cout << i+1;
for (int j = 0; j < graph[i].size(); j++)
cout << " " << graph[i][j].first;
cout << endl;
}
return 0;
}