Submission #3202054


Source Code Expand

Copy
/*input
13 17
BBABBBAABABBA
7 1
7 9
11 12
3 9
11 9
2 1
11 5
12 11
10 8
1 11
1 8
7 7
9 10
8 8
8 12
6 2
13 11
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

int n,m;
string s;
vector<int> edge[maxn];
vector<int> q;
int pt=0;

int A[maxn],B[maxn];

bool vis[maxn];

int main()
{
	cin>>n>>m>>s;
	while(m--){
		int u,v;
		cin>>u>>v;
		u--;v--;
		edge[u].pb(v);
		edge[v].pb(u);
		if(s[v]=='A') A[u]++;
		else B[u]++;
		if(s[u]=='A') A[v]++;
		else B[v]++;
	}
	REP(i,n) if(A[i]==0||B[i]==0){
		q.pb(i);
		vis[i]=1;
	}
	while(pt<SZ(q)){
		int cur=q[pt++];
		for(int v:edge[cur]) if(!vis[v]){
			if(s[cur]=='A') A[v]--;
			else B[v]--;
			if(A[v]<=0||B[v]<=0){
				q.pb(v);
				vis[v]=1;
			}
		}
	}
	REP(i,n) if(!vis[i]){
		cout<<"Yes\n";
		return 0;
	}
	cout<<"No\n";
	return 0;
}

Submission Info

Submission Time
Task C - ABland Yard
User iloveUtaha
Language C++14 (GCC 5.4.1)
Score 900
Code Size 2310 Byte
Status
Exec Time 195 ms
Memory 16000 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt
All 900 / 900 sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt, test_22.txt, test_23.txt, test_24.txt, test_25.txt, test_26.txt, test_27.txt, test_28.txt, test_29.txt, test_30.txt, test_31.txt, test_32.txt, test_33.txt, test_34.txt, test_35.txt, test_36.txt, test_37.txt, test_38.txt, test_39.txt, test_40.txt, test_41.txt, test_42.txt, test_43.txt, test_44.txt, test_45.txt, test_46.txt, test_47.txt, test_48.txt, test_49.txt, test_50.txt, test_51.txt, test_52.txt, test_53.txt, test_54.txt, test_55.txt
Case Name Status Exec Time Memory
sample_01.txt 3 ms 7936 KB
sample_02.txt 3 ms 7936 KB
sample_03.txt 3 ms 7936 KB
sample_04.txt 3 ms 7936 KB
test_01.txt 146 ms 14592 KB
test_02.txt 148 ms 15104 KB
test_03.txt 87 ms 12156 KB
test_04.txt 122 ms 12928 KB
test_05.txt 106 ms 13824 KB
test_06.txt 82 ms 11520 KB
test_07.txt 45 ms 10240 KB
test_08.txt 80 ms 11264 KB
test_09.txt 66 ms 11260 KB
test_10.txt 44 ms 10112 KB
test_11.txt 145 ms 14592 KB
test_12.txt 150 ms 14340 KB
test_13.txt 88 ms 12156 KB
test_14.txt 133 ms 13692 KB
test_15.txt 108 ms 12928 KB
test_16.txt 59 ms 8960 KB
test_17.txt 80 ms 9856 KB
test_18.txt 61 ms 9216 KB
test_19.txt 101 ms 9728 KB
test_20.txt 82 ms 10112 KB
test_21.txt 81 ms 9728 KB
test_22.txt 148 ms 14332 KB
test_23.txt 106 ms 12288 KB
test_24.txt 165 ms 12800 KB
test_25.txt 129 ms 11264 KB
test_26.txt 192 ms 15612 KB
test_27.txt 101 ms 12924 KB
test_28.txt 52 ms 11644 KB
test_29.txt 127 ms 12160 KB
test_30.txt 38 ms 8832 KB
test_31.txt 149 ms 14844 KB
test_32.txt 101 ms 13952 KB
test_33.txt 187 ms 13824 KB
test_34.txt 37 ms 9856 KB
test_35.txt 195 ms 16000 KB
test_36.txt 3 ms 7936 KB
test_37.txt 4 ms 7936 KB
test_38.txt 4 ms 7936 KB
test_39.txt 3 ms 7936 KB
test_40.txt 3 ms 7936 KB
test_41.txt 3 ms 7936 KB
test_42.txt 3 ms 7936 KB
test_43.txt 3 ms 7936 KB
test_44.txt 4 ms 7936 KB
test_45.txt 4 ms 7936 KB
test_46.txt 3 ms 7936 KB
test_47.txt 3 ms 7936 KB
test_48.txt 4 ms 7936 KB
test_49.txt 3 ms 7936 KB
test_50.txt 3 ms 7936 KB
test_51.txt 4 ms 7936 KB
test_52.txt 4 ms 7936 KB
test_53.txt 3 ms 7936 KB
test_54.txt 3 ms 7936 KB
test_55.txt 3 ms 7936 KB