Submission #3222778


Source Code Expand

Copy
#include <bits/stdc++.h>

using namespace std;

#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define FOR(i,n) for (int i = 0; i < n; i++)
#define FORR(i,a,b) for (int i = a; i <= b; i++)
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<ii> vii;

const int MX = 200005;
int n, m, a, b, c[MX], x[MX][2];
char ch;
vi adj[MX];
bitset<MX> ex;
queue<int> q;

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		cin >> ch;
		c[i] = ch == 'A';
		ex[i] = 1;
	}

	while (m--) {
		cin >> a >> b;
		adj[a].pb(b);
		if (a != b) adj[b].pb(a);

		x[a][c[b]]++;
		if (a != b) x[b][c[a]]++;
	}

	for (int i = 1; i <= n; i++)
		if (!x[i][0] || !x[i][1]) {
			q.push(i);
			ex[i] = 0;
		}

	while (q.size()) {
		int u = q.front();
		q.pop();

		for (int v : adj[u]) {
			x[v][c[u]]--;
			if ((!x[v][0] || !x[v][1]) && ex[v]) {
				q.push(v);
				ex[v] = 0;
			}
		}
	}

	if (ex.count()) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Submission Info

Submission Time
Task C - ABland Yard
User Marckess
Language C++14 (GCC 5.4.1)
Score 900
Code Size 1290 Byte
Status
Exec Time 86 ms
Memory 12928 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 6400 KB
sample_02.txt 3 ms 6400 KB
sample_03.txt 3 ms 6400 KB
sample_04.txt 3 ms 6400 KB
test_01.txt 61 ms 11648 KB
test_02.txt 66 ms 11648 KB
test_03.txt 38 ms 9472 KB
test_04.txt 48 ms 10752 KB
test_05.txt 47 ms 10112 KB
test_06.txt 34 ms 9472 KB
test_07.txt 20 ms 8064 KB
test_08.txt 33 ms 9344 KB
test_09.txt 28 ms 8704 KB
test_10.txt 20 ms 7936 KB
test_11.txt 63 ms 11648 KB
test_12.txt 61 ms 11648 KB
test_13.txt 38 ms 9472 KB
test_14.txt 55 ms 10752 KB
test_15.txt 47 ms 10112 KB
test_16.txt 19 ms 7424 KB
test_17.txt 25 ms 8320 KB
test_18.txt 20 ms 7680 KB
test_19.txt 30 ms 8192 KB
test_20.txt 26 ms 8704 KB
test_21.txt 31 ms 8192 KB
test_22.txt 64 ms 11264 KB
test_23.txt 47 ms 9856 KB
test_24.txt 66 ms 10624 KB
test_25.txt 50 ms 9472 KB
test_26.txt 85 ms 12416 KB
test_27.txt 44 ms 10496 KB
test_28.txt 24 ms 9344 KB
test_29.txt 52 ms 9984 KB
test_30.txt 16 ms 7296 KB
test_31.txt 66 ms 11776 KB
test_32.txt 47 ms 11008 KB
test_33.txt 72 ms 11136 KB
test_34.txt 17 ms 7808 KB
test_35.txt 86 ms 12928 KB
test_36.txt 3 ms 6400 KB
test_37.txt 3 ms 6400 KB
test_38.txt 3 ms 6400 KB
test_39.txt 3 ms 6400 KB
test_40.txt 3 ms 6400 KB
test_41.txt 3 ms 6400 KB
test_42.txt 3 ms 6400 KB
test_43.txt 3 ms 6400 KB
test_44.txt 3 ms 6400 KB
test_45.txt 3 ms 6400 KB
test_46.txt 3 ms 6400 KB
test_47.txt 3 ms 6400 KB
test_48.txt 3 ms 6400 KB
test_49.txt 3 ms 6400 KB
test_50.txt 3 ms 6400 KB
test_51.txt 3 ms 6400 KB
test_52.txt 3 ms 6400 KB
test_53.txt 3 ms 6400 KB
test_54.txt 3 ms 6400 KB
test_55.txt 3 ms 6400 KB