Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _USE_MATH_DEFINES
- #include <iostream>
- #include <conio.h>
- #include <string>
- #include <set>
- #include <map>
- #include <algorithm>
- #include <string>
- #include <math.h>
- #include <vector>
- #include <cmath>
- #include <sstream>
- #include <queue>
- using namespace std;
- struct player
- {
- string sname;
- bool was;
- map <string, player*> teammades;
- };
- player* NEW(string name)
- {
- player* New = new player;
- New->sname = name;
- New->was = false;
- return New;
- }
- map <string, player*> friends;
- void graf(vector <string> data)
- {
- for (int i = 0; i <= 2; i++)
- for (int j = 0; j <= 2; j++)
- if (j != i)
- if (friends[data[i]]->teammades.find(data[j]) == friends[data[i]]->teammades.end())
- friends[data[i]]->teammades.insert(pair <string, player*>(data[j], friends[data[j]]));
- }
- map <string, int> answer;
- queue <player*> Next;
- void find(player* friends, int n)
- {
- Next.push(friends);
- answer.insert(pair <string, int>(friends->sname, n));
- while (!Next.empty())
- {
- player* to = new player;
- to = Next.front();
- Next.pop();
- n++;
- for (auto i = to->teammades.begin(); i != to->teammades.end(); i++)
- {
- player* to1 = new player;
- to1 = i->second;
- if (!to1->was)
- {
- to1->was = true;
- Next.push(to1);
- answer.insert(pair <string, int>(to1->sname, answer[to->sname] + 1));
- }
- }
- }
- }
- int main()
- {
- player* team = new player;
- vector <string> data;
- string prom;
- int n;
- cin >> n;
- for (int i = 1; i <= n; i++)
- {
- cin >> prom;
- data.push_back(prom);
- cin >> prom;
- data.push_back(prom);
- cin >> prom;
- data.push_back(prom);
- if (friends.find(data[0]) == friends.end())
- friends.insert(pair <string, player*>(data[0], NEW(data[0])));
- if (friends.find(data[1]) == friends.end())
- friends.insert(pair <string, player*>(data[1], NEW(data[1])));
- if (friends.find(data[2]) == friends.end())
- friends.insert(pair <string, player*>(data[2], NEW(data[2])));
- graf(data);
- data.clear();
- }
- auto j = friends.begin();
- if (friends.find("Isenbaev") != friends.end())
- {
- answer.insert(pair <string, int>("Isenbaev", 0));
- find(friends["Isenbaev"], 0);
- }
- bool promq = false;
- if(answer.size()!=0)
- for (auto i = answer.begin(); i != answer.end(); i++)
- {
- if (promq == true)
- i--;
- if (i->first == j->first)
- {
- promq = false;
- cout << i->first << " ";
- cout << i->second << endl;
- }
- else
- {
- promq = true;
- cout << j->first << " ";
- cout << "undefined" << endl;
- }
- j++;
- }
- while (j != friends.end())
- {
- cout << j->first << " ";
- cout << "undefined" << endl;
- j++;
- }
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment