Advertisement
Guest User

Untitled

a guest
Jan 17th, 2019
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.36 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <cstdlib>
  3. #define pfor(i, n) for (int i = 0; i < (n); i++)
  4. #define rfor(i, n) for (int i = (n) - 1; i >= 0; i--)
  5. #define pb push_back
  6. #define fi first
  7. #define se second
  8. #define _USE_MATH_DEFINES
  9. #define gb(x, i) ((x >> i) & 1)
  10.  
  11. using namespace std;
  12. typedef long long ll;
  13.  
  14. const int N = 300;
  15.  
  16. map <string, int> w[N], a[N];
  17.  
  18. vector <string> v;
  19.  
  20. set <string> s;
  21.  
  22. void bfs(string st) {
  23.     w[st] = 1;
  24.     queue <string> q;
  25.     q.push(st);
  26.     while (!q.empty()) {
  27.         string u = q.front();
  28.         q.pop();
  29.         pfor(i, v[u].size()) {
  30.             string to = v[u][i];
  31.             if (w[to] == 0) {
  32.                 a[to] = a[u] + 1;
  33.                 q.push(to);
  34.             }
  35.         }
  36.     }
  37. }
  38.  
  39. string sm(string st) {
  40.     pfor(i, st.size()) {
  41.         if (st[i] >= 'A' && st[i] <= 'Z') {
  42.             st[i] = st[i] - 'A' + 'a';
  43.         }
  44.     }
  45.     return st;
  46. }
  47.  
  48. int main() {
  49.     ios_base::sync_with_stdio(0);
  50.     cin.tie(0);
  51.     cout.tie(0);
  52.     int n;
  53.     cin >> n;
  54.     pfor(i, n) {
  55.         string s1, s2, s3;
  56.         cin >> s1 >> s2 >> s3;
  57.         s1 = sm(s1);
  58.         s3 = sm(s3);
  59.         v[s3].pb(s1);
  60.         s.insert(s1);
  61.         s.insert(s3);
  62.     }
  63.     bfs('polycarp');
  64.     int ans = 0;
  65.     for (auto i : s) {
  66.         ans = max(ans, a[i]);
  67.     }
  68.     cout << ans;
  69.     return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement