➤ Problem Link : 522A. Reposts
✅ C++ Solution :
#include<bits/stdc++.h>
using namespace std;
int dfs(string s,map<string,vector<string> > mp)
{
int val=0;
for(int i=0;i<mp[s].size();i++)
{
val=max(val,dfs(mp[s][i],mp));
}
return 1+val;
}
int main()
{
int n;
cin>>n;
map<string,vector<string> > mp;
string s1,s2,s3;
for(int i=0;i<n;i++)
{
cin>>s1>>s2>>s3;
for(int j=0;j<s1.length();j++)
s1[j]=tolower(s1[j]);
for(int j=0;j<s3.length();j++)
s3[j]=tolower(s3[j]);
mp[s3].push_back(s1);
}
cout<<dfs("polycarp",mp);
}
Thank you for your patience reading. If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Whatsapp or Facebook.
😇Happy Learning!!
