分析

其实题目说得很清楚了,就是每一个不同的字符串是否都对应一个天敌(map搞定一切),锅主要是在题目中
的字符串,相信很多人第一次看就只输入了字符

代码

//#pragma GCC optimize(3,"inline","Ofast","fast-math","no-stack-protector","unroll-loops")
//#pragma GCC target("sse","sse2","sse3","sse4","avx","avx2","popcnt")

#include<bits/stdc++.h>

#define R register
#define ll long long
#define inf INT_MAX

using namespace std;

const int N=1e5+10;
const ll mod=1e9+7;

int n;

map<string,bool>vis;
vector<string>q;
map<string,int>din;

int main()
{
    cin>>n;
    for (int i=1;i<=n;i++)
    {
        string x,y;
        cin>>x>>y;
        if(!vis[x])
            vis[x]=1,q.push_back(x);
        if(!vis[y])
            vis[y]=1,q.push_back(y);
        din[y]++;
    }

    int len=q.size(),kl=1;
    for (int i=0;i<len;i++)
        if(!din[q[i]]) kl=0;

    cout<<kl<<"\n";

    return 0;
}