N00bCode's blog

By N00bCode, history, 17 months ago, In English

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;
}

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it