Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdio.h"
- #include <iostream>
- #include <string>
- #include <map>
- #include <algorithm>
- #include <vector>
- using namespace std;
- int max1;
- int n;
- map<string, vector<string>> l;
- map<string, bool> used;
- void dfs(int counter, string s){
- used[s]=true;
- for (int i = 0; i<l[s].size(); i++) {
- if (!used[l[s][i]]) {
- dfs(counter+1, l[s][i]);
- max1 = max1 < counter ? counter : max1;
- }
- }
- }
- int main()
- {
- max1 =0;
- cin >> n;
- string n1,n2,re;
- string start;
- for (int i = 0; i <n; i++) {
- cin >> n1;
- cin >> re;
- cin >> n2;
- transform(n1.begin(), n1.end(), n1.begin(), ::tolower);
- transform(n2.begin(), n2.end(), n2.begin(), ::tolower);
- start = i == 0 ? n2 : start;
- l[n2].push_back(n1);
- }
- dfs(1, start);
- if (n!=0&&max1==1) {
- max1=2;
- }else{
- max1++;
- }
- cout << max1;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement