Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #include <cstdlib>
- #define pfor(i, n) for (int i = 0; i < (n); i++)
- #define rfor(i, n) for (int i = (n) - 1; i >= 0; i--)
- #define pb push_back
- #define fi first
- #define se second
- #define _USE_MATH_DEFINES
- #define gb(x, i) ((x >> i) & 1)
- using namespace std;
- typedef long long ll;
- const int N = 300;
- map <string, int> w[N], a[N];
- vector <string> v;
- set <string> s;
- void bfs(string st) {
- w[st] = 1;
- queue <string> q;
- q.push(st);
- while (!q.empty()) {
- string u = q.front();
- q.pop();
- pfor(i, v[u].size()) {
- string to = v[u][i];
- if (w[to] == 0) {
- a[to] = a[u] + 1;
- q.push(to);
- }
- }
- }
- }
- string sm(string st) {
- pfor(i, st.size()) {
- if (st[i] >= 'A' && st[i] <= 'Z') {
- st[i] = st[i] - 'A' + 'a';
- }
- }
- return st;
- }
- int main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- int n;
- cin >> n;
- pfor(i, n) {
- string s1, s2, s3;
- cin >> s1 >> s2 >> s3;
- s1 = sm(s1);
- s3 = sm(s3);
- v[s3].pb(s1);
- s.insert(s1);
- s.insert(s3);
- }
- bfs('polycarp');
- int ans = 0;
- for (auto i : s) {
- ans = max(ans, a[i]);
- }
- cout << ans;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement