Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <array>
- #include <iostream>
- #include <vector>
- #include <map>
- #include <queue>
- using namespace std;
- #define int long long
- const long long INF = 1e18 + 7;
- const int MAXN = 2e5 + 10;
- const int N = 2e5;
- signed main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- int n;
- cin >> n;
- map<string, vector<string>> mp;
- for (int i = 0; i < n; ++i) {
- string name1, rep, name2;
- cin >> name1 >> rep >> name2;
- for (auto& elem: name1) {
- elem = tolower(elem);
- }
- for (auto& elem: name2) {
- elem = tolower(elem);
- }
- mp[name2].emplace_back(name1);
- }
- map<string, int> d;
- queue<string> q;
- string root = "polycarp";
- q.push(root);
- d[root] = 1;
- int ans = 0;
- while (!q.empty()) {
- string name = q.front();
- q.pop();
- for (const auto& to: mp[name]) {
- if (d[to] == 0) {
- d[to] = d[name] + 1;
- q.push(to);
- ans = max(ans, d[to]);
- }
- }
- }
- cout << ans << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment