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>
- using namespace std;
- struct player
- {
- bool was;
- map <string, player*> teammades;
- };
- player* NEW()
- {
- player* New = new player;
- 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]]));
- }
- set <int> sc;
- int find(player* friends, int n)
- {
- if (friends->teammades.find("Isenbaev") == friends->teammades.end())
- {
- if (friends->was != true)
- {
- n++;
- for (auto i = friends->teammades.begin(); i != friends->teammades.end(); i++)
- {
- friends->was = true;
- if (i->second->was != true)
- {
- find(i->second, n);
- }
- }
- friends->was = false;
- }
- }
- else
- sc.insert(n);
- return n;
- }
- 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()));
- if (friends.find(data[1]) == friends.end())
- friends.insert(pair <string, player*>(data[1], NEW()));
- if (friends.find(data[2]) == friends.end())
- friends.insert(pair <string, player*>(data[2], NEW()));
- graf(data);
- data.clear();
- }
- for (auto i = friends.begin(); i != friends.end(); i++)
- {
- cout << i->first << " ";
- find(i->second, 0);
- if (i->first != "Isenbaev")
- if (sc.size() != 0)
- cout << *sc.begin() + 1 << endl;
- else
- cout << "undefined" << endl;
- else
- cout << 0 << endl;
- sc.clear();
- }
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment