I can't figure out which test cases are failing in this approach for the problem given.

Правка en1, от N00bCode, 2023-01-20 13:18:57

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;
}
Теги graphs, dfs, hashmap, c++, algorithms, adhoc

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский N00bCode 2023-01-20 13:18:57 830 Initial revision (published)