Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- //declaration
- // vector<int> v(4);
- // for (int i = 0; i < 4; i++) cin >> v[i];
- // for (int i = 0; i < 4; i++) cout << v[i] << " ";
- // cout << endl;
- // vector<int> v;//empty vector
- // int n; cin >> n;
- //push_back()->insertion and size allocation at the same time
- // for (int i = 0; i < n; i++)
- // {
- // int x; cin >> x;
- // v.push_back(x);
- // }
- //v -> curr size==n
- // int x; cin >> x;
- // v.push_back(x);
- //v.size()->current size of the vector
- // v-> {1,2,3} v.size()=3
- // indexes->{0,1,2}
- // for (int i = 0; i < v.size(); i++)
- // {
- // cout << "Index-> " << i << "Curr_element-> " << v[i] << endl;
- // }
- //v.pop_back()
- // for (int i = 0; i < v.size(); i++)
- // {
- // cout << v[i] << " ";
- // }
- // cout << endl;
- // cout << v.size() << " vector_curr_size " << endl;
- // v.pop_back();
- // cout << v.size() << " vector_curr_size " << endl;
- // for (int i = 0; i < v.size(); i++)
- // {
- // cout << v[i] << " ";
- // }
- //vector<char> v;
- //vector<string> v;
- // vector<string> v;
- // cout << v.size() << endl;
- // int n; cin >> n;
- // for (int i = 0; i < n; i++)
- // {
- // // cin >> v[i];->this will give error
- // string temp; cin >> temp;
- // v.push_back(temp);
- // cout << v.size() << endl;
- // // v.push_back(v[i])
- // }
- // for (int i = 0; i < v.size(); i++)
- // {
- // cout << v[i] << " ";
- // }
- // cout << endl;
- //vector<pair<int,int>>;
- //declaration
- // pair<string, string> p;
- // cin >> p.first >> p.second;
- // cout << p.first << " " << p.second << " " << endl;
- // vector<pair<string, int>> v;
- // int n; cin >> n;
- // for (int i = 0; i < n; i++)
- // {
- // pair<string, int> temp_pair;
- // cin >> temp_pair.first >> temp_pair.second;
- // v.push_back(temp_pair);
- // }
- // cout << v.size() << endl;
- // for (int i = 0; i < v.size(); i++)
- // {
- // cout << v[i].first << " " << v[i].second << " " << endl;
- // }
- // vector<pair<string, pair<string, int>>> v(3);
- // for (int i = 0; i < v.size(); i++)
- // {
- // cin >> v[i].first >> v[i].second.first >> v[i].second.second;
- // }
- // cout << v.size() << endl; //->curr size
- // for (int i = 0; i < v.size(); i++)
- // {
- // cout << "Stu_Name " << v[i].first << " " << "Skill_Name " << v[i].second.first << " " << "Skill_Lev " << v[i].second.second << " " << endl;
- // }
- int n, m; cin >> n >> m;
- //n number of nodes, m number of edges
- vector<vector<pair<int, int>>> v(n + 1);
- for (int i = 1; i <= m; i++)
- {
- int a, b, w; cin >> a >> b >> w;
- //a is connected to b with weight w
- //b is connected to a with weight w
- //or we can also say that
- //b is the children of a with weight w
- //a is the children of b with weight w
- v[a].push_back(make_pair(b, w));
- v[b].push_back(make_pair(a, w));
- }
- for (int i = 1; i < v.size(); i++)
- {
- cout << "Parent-> " << i << " " << endl;
- for (int j = 0; j < v[i].size(); j++)
- {
- cout << "Child " << v[i][j].first << " " << "Weight " << v[i][j].second << " " << endl;
- }
- cout << endl; cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement