RE求助
查看原帖
RE求助
361112
summer2020楼主2023/2/8 14:02
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<vector>
#include<map>
#include<queue>
using namespace std;
const int N=1e5+1;
vector<long long> g[N];
string str_1,str_2,ax[N];
map<string,long long> mp;
queue<long long> q;
long long a,rd[N],cnt;
bool bl[N];
int main()
{
	memset(bl,false,sizeof(bl));
	scanf("%lld",&a);
	for(int i=1;i<=a;i++)
	{
		cin>>str_1>>str_2;
		if(!mp[str_1])
		{
			mp[str_1]=++cnt;
			ax[cnt]=str_1;
		}
		if(!mp[str_2])
		{
			mp[str_2]=++cnt;
			ax[cnt]=str_2;
		}
		g[mp[str_1]].push_back(mp[str_2]);
		rd[mp[str_2]]++;
	}
//	for(int i=1;i<=cnt;i++)cout<<ax[i]<<" "<<rd[i]<<" "<<"\n";
	for(int i=1;i<=cnt;i++)if(rd[i]==0)q.push(i);
	while(!q.empty())
	{
		long long pos=q.front();
		q.pop();
		bl[pos]=true;
		//	cout<<">>"<<ax[pos]<<"\n";
		for(int i=0;i<g[pos].size();i++)
		{
			rd[g[pos][i]]--;
			if(rd[g[pos][i]]==0&&bl[g[pos][i]]==false)q.push(g[pos][i]);
		}
	}
	for(int i=1;i<=cnt;i++)
	{
		if(rd[i]>0)
		{
			puts("No");
			return 0;
		}
	}
	puts("Yes");
	return 0;
}

AC 8 RE 12 WA 2

2023/2/8 14:02
加载中...