Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int n;
- vector<pair<string, string>> a;
- vector<int> d;
- void normalize (string &s)
- {
- for (int i = 0; i < s.length(); i++)
- if (s[i] >= 'A' && s[i] <= 'Z')
- s[i] = s[i] - 'A' + 'a';
- }
- int calc (int q)
- {
- if(d[q] != -1)
- return d[q];
- d[q] = 1;
- for (int i = 0; i < n; i++)
- if (a[i].second == a[q].first)
- d[q] = max(d[q], calc(i) + 1);
- return d[q];
- }
- int main()
- {
- cin >> n;
- a = vector<pair<string, string>> (n);
- d = vector<int> (n, -1);
- for (int i = 0; i < n; i++)
- {
- string s1, s2, s3;
- cin >> s1 >> s2 >> s3;
- normalize(s1);
- normalize(s3);
- a[i] = {s1, s3};
- }
- int result = 1;
- for (int i = 0; i < n; i++)
- if (a[i].second == "polycarp")
- result = max(result, calc(i) + 1);
- cout << result << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement