提出 #38053973


ソースコード 拡げる

#include<bits/stdc++.h>
#define N 1000009
using namespace std;
typedef long long ll;
inline ll rd(){
	ll x=0;char c=getchar();bool f=0;
	while(!isdigit(c)){if(c=='-')f=1;c=getchar();}
	while(isdigit(c)){x=(x<<1)+(x<<3)+(c^48);c=getchar();}
	return f?-x:x;
}
string s[N],t[N];
int tot=0;
int head[N],du[N];
map<string,int>mp;
struct edge{
	int n,to;
}e[N<<1];
void add(int u,int v){
	e[++tot].n=head[u];
	e[tot].to=v;
	head[u]=tot;
	du[v]++;
} 
queue<int>q;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n;
	cin>>n;
	int num=0;
	for(int i=1;i<=n;++i){
		cin>>s[i]>>t[i];
		if(!mp[s[i]])
			mp[s[i]]=++num;
		if(!mp[t[i]])
			mp[t[i]]=++num;
		add(mp[s[i]],mp[t[i]]);
	}
	for(int i=1;i<=num;++i)if(!du[i])
		q.push(i);
	while(!q.empty()){
		int u=q.front();q.pop();
		for(int i=head[u];i;i=e[i].n){
			int v=e[i].to;
			if(!--du[v])q.push(v);
		}
	}
	int gg=0;
	for(int i=1;i<=num;++i)if(du[i])gg=1;
	if(gg)cout<<"No";
	else cout<<"Yes";
    return 0;
}

提出情報

提出日時
問題 D - Change Usernames
ユーザ comld
言語 C++ (GCC 9.2.1)
得点 400
コード長 1032 Byte
結果 AC
実行時間 252 ms
メモリ 84488 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 400 / 400
結果
AC × 3
AC × 22
セット名 テストケース
Sample sample_01.txt, sample_02.txt, sample_03.txt
All random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, sample_01.txt, sample_02.txt, sample_03.txt
ケース名 結果 実行時間 メモリ
random_01.txt AC 242 ms 84488 KiB
random_02.txt AC 252 ms 84456 KiB
random_03.txt AC 180 ms 75332 KiB
random_04.txt AC 199 ms 75500 KiB
random_05.txt AC 177 ms 75368 KiB
random_06.txt AC 196 ms 75508 KiB
random_07.txt AC 185 ms 75484 KiB
random_08.txt AC 209 ms 75504 KiB
random_09.txt AC 196 ms 75496 KiB
random_10.txt AC 201 ms 76320 KiB
random_11.txt AC 207 ms 77444 KiB
random_12.txt AC 214 ms 78320 KiB
random_13.txt AC 221 ms 79220 KiB
random_14.txt AC 195 ms 75568 KiB
random_15.txt AC 200 ms 76148 KiB
random_16.txt AC 206 ms 77556 KiB
random_17.txt AC 213 ms 78504 KiB
random_18.txt AC 219 ms 79200 KiB
random_19.txt AC 52 ms 66000 KiB
sample_01.txt AC 47 ms 66032 KiB
sample_02.txt AC 50 ms 66000 KiB
sample_03.txt AC 49 ms 66004 KiB