Advertisement
Guest User

Untitled

a guest
May 27th, 2015
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. #include "stdio.h"
  2. #include <iostream>
  3. #include <string>
  4. #include <map>
  5. #include <algorithm>
  6. #include <vector>
  7. using namespace std;
  8. int max1;
  9. int n;
  10. map<string, vector<string>> l;
  11. map<string, bool> used;
  12. void dfs(int counter, string s){
  13. used[s]=true;
  14. for (int i = 0; i<l[s].size(); i++) {
  15. if (!used[l[s][i]]) {
  16. dfs(counter+1, l[s][i]);
  17. max1 = max1 < counter ? counter : max1;
  18. }
  19. }
  20. }
  21.  
  22. int main()
  23. {
  24. max1 =0;
  25. cin >> n;
  26. string n1,n2,re;
  27. string start;
  28. for (int i = 0; i <n; i++) {
  29. cin >> n1;
  30. cin >> re;
  31. cin >> n2;
  32. transform(n1.begin(), n1.end(), n1.begin(), ::tolower);
  33. transform(n2.begin(), n2.end(), n2.begin(), ::tolower);
  34. start = i == 0 ? n2 : start;
  35. l[n2].push_back(n1);
  36. }
  37.  
  38. dfs(1, start);
  39. if (n!=0&&max1==1) {
  40. max1=2;
  41. }else{
  42. max1++;
  43. }
  44. cout << max1;
  45. return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement