Problem: AtCoder
code:
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
map<string,string> inp;
map<string, int> vis,ininp;
for(int i=0;i<n;i++){
string a,b;
cin>>a>>b;
inp[a]=b;
ininp[a]++;
}
string ans="Yes";
for(auto e: inp){
if(vis[e.first]) continue;
vis[e.first]++;
string temp=inp[e.first];
while(ininp[temp]){
if(vis[temp]) {
ans="No";
break;
}
else vis[temp]++;
temp=inp[temp];
}
}
cout<<ans;
return 0;
}