Submission #43419668


Source Code Expand

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

namespace FastIO
{

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

class FastOutput final: public FastIOBase
{
#ifdef OPENIOBUF
 public:
	void flush()
	{ fwrite(buf,1,buf_p,target),buf_p=0; }
#endif
 private:
	void __putc(char x)
	{
#ifdef OPENIOBUF
		if(buf[buf_p++]=x,buf_p==BUFSIZE) flush();
#else
		putc(x,target);
#endif
	}
	template<typename T>
	void __write(T x)
	{
		char stk[64],*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
	FastOutput &operator <<(char x)
	{ return __putc(x),*this; }
	FastOutput &operator <<(const char *s)
	{ for(;*s;__putc(*(s++)));return *this; }
	FastOutput &operator <<(const string &s)
	{ return (*this)<<s.c_str(); }
	template<typename T>
	enable_if_t<is_integral<T>::value,FastOutput&> operator <<(const T &x)
	{ return __write(x),*this; }
	template<typename ...T>
	void writesp(const T &...x)
	{ initializer_list<int>{(this->operator<<(x),__putc(' '),0)...}; }
	template<typename ...T>
	void writeln(const T &...x)
	{ initializer_list<int>{(this->operator<<(x),__putc('\n'),0)...}; }
	template<typename Iter>
	void writesp(Iter begin,Iter end)
	{ while(begin!=end) (*this)<<*(begin++)<<' '; }
	template<typename Iter>
	void writeln(Iter begin,Iter end)
	{ while(begin!=end) (*this)<<*(begin++)<<'\n'; }
}qout;

class FastInput final: public FastIOBase
{
#ifdef OPENIOBUF
 public:
	void flush()
	{ buf[fread(buf,1,BUFSIZE,target)]=EOF,buf_p=0; }
#endif
 private:
	bool __eof;
	char __getc()
	{
		if(__eof) return EOF;
#ifdef OPENIOBUF
		if(buf_p==BUFSIZE) flush();
		char ch=buf[buf_p++];
#else
		char ch=getc(target);
#endif
		return ~ch?ch:(__eof=true,EOF);
	}
	void __ungetc(char c)
	{
		__eof=false;
#ifdef OPENIOBUF
		buf_p--;
#else
		ungetc(c,target);
#endif
	}
 public:
	FastInput(FILE *f=stdin): FastIOBase(f),__eof(false)
#ifdef OPENIOBUF
	{ buf_p=BUFSIZE; }
	bool eof()const { return buf[buf_p]==EOF; }
#else
	{}
	bool eof()const { return feof(target); }
#endif
	char peek() { return __getc(); }
	explicit operator bool()const { return !__eof; }
	FastInput &operator >>(char &x)
	{ while(isspace(x=__getc()));return *this; }
	template<typename T>
	enable_if_t<is_integral<T>::value,FastInput&> operator >>(T &x)
	{
		char ch,sym=0;x=0;
		while(isspace(ch=__getc()));
		if(__eof) return *this;
		if(ch=='-') sym=1,ch=__getc();
		for(x=0;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=__getc());
		return __ungetc(ch),sym?x=-x:x,*this;
	}
	FastInput &operator >>(char *s)
	{
		while(isspace(*s=__getc()));
		if(__eof) return *this;
		for(;!isspace(*s) && !__eof;*(++s)=__getc());
		return __ungetc(*s),*s='\0',*this;
	}
	FastInput &operator >>(string &s)
	{
		char str_buf[(1<<8)+1]={0},*p=str_buf;
		char *const buf_end=str_buf+(1<<8);
		while(isspace(*p=__getc()));
		if(__eof) return *this;
		for(s.clear(),p++;;p=str_buf)
		{
			for(;p!=buf_end && !isspace(*p=__getc()) && !__eof;p++);
			if(p!=buf_end) break;
			s.append(str_buf);
		}
		__ungetc(*p),*p='\0',s.append(str_buf);
		return *this;
	}
	template<typename ...T>
	void read(T &...x)
	{ initializer_list<int>{(this->operator>>(x),0)...}; }
	template<typename Iter>
	void read(Iter begin,Iter end)
	{ while(begin!=end) (*this)>>*(begin++); }
}qin;

} // namespace FastIO
using FastIO::qin,FastIO::qout;

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,m,a[200005],fa[200005];
struct Edge{ int u,v; }e[200005];
inline int findFa(int x)
{ return x!=fa[x]?fa[x]=findFa(fa[x]):x; }

int main()
{
	qin>>n>>m;
	for(int i=1;i<=m;i++)
		qin>>e[i].u>>e[i].v;
	qin.read(a+1,a+n+1);
	iota(fa+1,fa+n+1,1);
	bool ans=false;
	for(int i=1;i<=m;i++)
		if(a[e[i].u]!=a[e[i].v]) fa[findFa(e[i].u)]=findFa(e[i].v);
	for(int i=1;i<=m;i++)
		if(a[e[i].u]==a[e[i].v]) ans|=(findFa(e[i].u)==findFa(e[i].v));
	qout<<(ans?"Yes\n":"No\n");
	return 0;
}

Submission Info

Submission Time
Task B - Switching Travel
User balalida
Language C++ (GCC 9.2.1)
Score 500
Code Size 4571 Byte
Status AC
Exec Time 39 ms
Memory 12944 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 2
AC × 46
Set Name Test Cases
Sample sample-01.txt, sample-02.txt
All in-01.txt, in-02.txt, in-03.txt, in-04.txt, in-05.txt, in-06.txt, in-07.txt, in-08.txt, in-09.txt, in-10.txt, in-11.txt, in-12.txt, in-13.txt, in-14.txt, in-15.txt, in-16.txt, in-17.txt, in-18.txt, in-19.txt, in-20.txt, in-21.txt, in-22.txt, in-23.txt, in-24.txt, in-25.txt, in-26.txt, in-27.txt, in-28.txt, in-29.txt, in-30.txt, in-31.txt, in-32.txt, in-33.txt, in-34.txt, in-35.txt, in-36.txt, in-37.txt, in-38.txt, in-39.txt, in-40.txt, in-41.txt, in-42.txt, in-43.txt, in-44.txt, sample-01.txt, sample-02.txt
Case Name Status Exec Time Memory
in-01.txt AC 35 ms 6688 KiB
in-02.txt AC 37 ms 12944 KiB
in-03.txt AC 39 ms 12896 KiB
in-04.txt AC 36 ms 9680 KiB
in-05.txt AC 34 ms 9676 KiB
in-06.txt AC 27 ms 5432 KiB
in-07.txt AC 37 ms 6340 KiB
in-08.txt AC 20 ms 5140 KiB
in-09.txt AC 25 ms 5128 KiB
in-10.txt AC 10 ms 4104 KiB
in-11.txt AC 22 ms 5384 KiB
in-12.txt AC 16 ms 4880 KiB
in-13.txt AC 37 ms 6344 KiB
in-14.txt AC 27 ms 5900 KiB
in-15.txt AC 15 ms 4620 KiB
in-16.txt AC 11 ms 4200 KiB
in-17.txt AC 28 ms 5904 KiB
in-18.txt AC 6 ms 3832 KiB
in-19.txt AC 26 ms 5628 KiB
in-20.txt AC 17 ms 4836 KiB
in-21.txt AC 14 ms 4444 KiB
in-22.txt AC 12 ms 4120 KiB
in-23.txt AC 17 ms 4852 KiB
in-24.txt AC 6 ms 3788 KiB
in-25.txt AC 16 ms 4536 KiB
in-26.txt AC 29 ms 5908 KiB
in-27.txt AC 18 ms 4772 KiB
in-28.txt AC 6 ms 3796 KiB
in-29.txt AC 4 ms 3696 KiB
in-30.txt AC 26 ms 5216 KiB
in-31.txt AC 37 ms 6584 KiB
in-32.txt AC 12 ms 3968 KiB
in-33.txt AC 9 ms 4036 KiB
in-34.txt AC 33 ms 5500 KiB
in-35.txt AC 36 ms 6008 KiB
in-36.txt AC 2 ms 3516 KiB
in-37.txt AC 2 ms 3440 KiB
in-38.txt AC 2 ms 3536 KiB
in-39.txt AC 2 ms 3420 KiB
in-40.txt AC 19 ms 4556 KiB
in-41.txt AC 15 ms 4544 KiB
in-42.txt AC 37 ms 12936 KiB
in-43.txt AC 37 ms 12804 KiB
in-44.txt AC 32 ms 6668 KiB
sample-01.txt AC 2 ms 3448 KiB
sample-02.txt AC 2 ms 3584 KiB