提出 #38050043


ソースコード 拡げる

#include <bits/stdc++.h>
using namespace std;
//#define OPENIOBUF

namespace FastIO
{

class FastIOBase
{
 protected:
#ifdef OPENIOBUF
	static const int BUFSIZE=1<<22;
	char buf[BUFSIZE+1];
	int buf_p=0;
#endif
	FILE *target;
 public:
#ifdef OPENIOBUF
	virtual void flush()=0;
#endif
	FastIOBase(FILE *f): target(f){}
	~FastIOBase()=default;
};

class FastOutput: public FastIOBase
{
#ifdef OPENIOBUF
 public:
	inline void flush()
		{ fwrite(buf,1,buf_p,target),buf_p=0; }
#endif
 protected:
	inline void __putc(char x)
	{
#ifdef OPENIOBUF
		if(buf[buf_p++]=x,buf_p==BUFSIZE)flush();
#else
		putc(x,target);
#endif
	}
	template<typename T>
	inline void __write(T x)
	{
		static char stk[64],*top;top=stk;
		if(x<0) return __putc('-'),__write(-x);
		do *(top++)=x%10,x/=10; while(x);
		for(;top!=stk;__putc(*(--top)+'0'));
	}
 public:
	FastOutput(FILE *f=stdout): FastIOBase(f){}
#ifdef OPENIOBUF
	~FastOutput(){ flush(); }
#endif
	template<typename ...T>
	inline void writesp(const T &...x)
		{ initializer_list<int>{(this->operator<<(x),__putc(' '),0)...}; }
	template<typename ...T>
	inline void writeln(const T &...x)
		{ initializer_list<int>{(this->operator<<(x),__putc('\n'),0)...}; }
	inline FastOutput &operator <<(char x)
		{ return __putc(x),*this; }
	inline FastOutput &operator <<(const char *s)
		{ for(;*s;__putc(*(s++)));return *this; }
	inline FastOutput &operator <<(const string &s)
		{ return (*this)<<s.c_str(); }
	template<typename T,typename=typename enable_if<is_integral<T>::value>::type>
	inline FastOutput &operator <<(const T &x)
		{ return __write(x),*this; }
}qout;

class FastInput: public FastIOBase
{
#ifdef OPENIOBUF
 public:
	inline void flush()
		{ buf[fread(buf,1,BUFSIZE,target)]='\0',buf_p=0; }
#endif
 protected:
	inline char __getc()
	{
#ifdef OPENIOBUF
		if(buf_p==BUFSIZE) flush();
		return buf[buf_p++];
#else
		return getc(target);
#endif
	}
 public:
#ifdef OPENIOBUF
	FastInput(FILE *f=stdin): FastIOBase(f){ buf_p=BUFSIZE; }
#else
	FastInput(FILE *f=stdin): FastIOBase(f){}
#endif
	inline char getchar() { return __getc(); }
	template<typename ...T>
	inline void read(T &...x)
		{ initializer_list<int>{(this->operator>>(x),0)...}; }
	inline FastInput &operator >>(char &x)
		{ while(isspace(x=__getc()));return *this; }
	template<typename T,typename=typename enable_if<is_integral<T>::value>::type>
	inline FastInput &operator >>(T &x)
	{
		static char ch,sym;x=sym=0;
		while(isspace(ch=__getc()));
		if(ch=='-') sym=1,ch=__getc();
		for(;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=__getc());
		return sym?x=-x:x,*this;
	}
	inline FastInput &operator >>(char *s)
	{
		while(isspace(*s=__getc()));
		for(;!isspace(*s) && *s && ~*s;*(++s)=__getc());
		return *s='\0',*this;
	}
	inline FastInput &operator >>(string &s)
	{
		char str_buf[(1<<8)+1],*p=str_buf;
		char *const buf_end=str_buf+(1<<8);
		while(isspace(*p=__getc()));
		for(s.clear(),p++;;p=str_buf)
		{
			for(;p!=buf_end && !isspace(*p=__getc()) && *p && ~*p;p++);
			*p='\0',s.append(str_buf);
			if(p!=buf_end) break;
		}
		return *this;
	}
}qin;

} // namespace FastIO
using namespace FastIO;

using LL=long long;
using LD=long double;
using UI=unsigned int;
using ULL=unsigned long long;

#ifndef DADALZY
#define FILEIO(file) freopen(file".in","r",stdin),freopen(file".out","w",stdout)
#else
#define FILEIO(file)
#endif

int n,deg[100005];
string s[100005],t[100005];
map<string,int> mps,mpt;
vector<int> g[100005];
int main()
{
	qin>>n;
	for(int i=1;i<=n;i++)
	{
		qin>>s[i]>>t[i];
		mps[s[i]]=i,mpt[t[i]]=i;
	}
	for(int i=1,j;i<=n;i++)
	{
		if((j=mpt[s[i]])) g[i].push_back(j),deg[j]++;
		if((j=mps[t[i]])) g[j].push_back(i),deg[i]++;
	}
	queue<int> q;
	for(int i=1;i<=n;i++) if(!deg[i]) q.push(i);
	int tot=0;
	while(!q.empty())
	{
		int u=q.front();q.pop(),tot++;
		for(auto &v: g[u]) if(!--deg[v]) q.push(v);
	}
	qout<<(tot<n?"No":"Yes");
	return 0;
}

提出情報

提出日時
問題 D - Change Usernames
ユーザ balalida
言語 C++ (GCC 9.2.1)
得点 400
コード長 4034 Byte
結果 AC
実行時間 379 ms
メモリ 43580 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 349 ms 43424 KiB
random_02.txt AC 379 ms 43580 KiB
random_03.txt AC 322 ms 31168 KiB
random_04.txt AC 311 ms 31236 KiB
random_05.txt AC 252 ms 31196 KiB
random_06.txt AC 297 ms 31200 KiB
random_07.txt AC 266 ms 31196 KiB
random_08.txt AC 312 ms 31332 KiB
random_09.txt AC 317 ms 31456 KiB
random_10.txt AC 306 ms 32504 KiB
random_11.txt AC 307 ms 34312 KiB
random_12.txt AC 320 ms 35560 KiB
random_13.txt AC 345 ms 36596 KiB
random_14.txt AC 331 ms 31460 KiB
random_15.txt AC 352 ms 32372 KiB
random_16.txt AC 344 ms 34196 KiB
random_17.txt AC 327 ms 35620 KiB
random_18.txt AC 339 ms 36504 KiB
random_19.txt AC 12 ms 12088 KiB
sample_01.txt AC 11 ms 12104 KiB
sample_02.txt AC 11 ms 12044 KiB
sample_03.txt AC 13 ms 12064 KiB