Submission #3208481


Source Code Expand

Copy
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧  
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     
    /   \    | |     
    /   / ̄ ̄ ̄ ̄/  |  
  __(__ニつ/     _/ .| .|____  
     \/____/ (u ⊃  
---------------------------------------------------------------------------------------------------*/





int N, M; string S;
set<int> E[201010];
int ok[201010], ok2[201010];
int acnt[201010], bcnt[201010];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> M >> S;
    rep(i, 0, M) {
        int a, b; cin >> a >> b;
        a--; b--;
        E[a].insert(b);
        E[b].insert(a);
    }

    rep(cu, 0, N) {
        int a = 0, b = 0;
        fore(to, E[cu]) {
            if (S[to] == 'A') a++;
            else b++;
        }
        if (0 < a and 0 < b) ok[cu] = 1;
    }

    rep(cu, 0, N) if (ok[cu]) {
        fore(to, E[cu]) if(ok[to]) {
            if (S[to] == 'A') acnt[cu]++;
            else bcnt[cu]++;
        }
    }

    queue<int> ng;
    rep(cu, 0, N) if (ok[cu]) {
        if (acnt[cu] == 0 or bcnt[cu] == 0) {
            ng.push(cu);
            ok[cu] = 0;
        }
    }

    while (!ng.empty()) {
        int cu = ng.front(); ng.pop();

        fore(to, E[cu]) if (ok[to]) {
            if (S[cu] == 'A') acnt[to]--;
            else bcnt[to]--;

            if (acnt[to] == 0 or bcnt[to] == 0) {
                ng.push(to);
                ok[to] = 0;
            }
        }
    }

    rep(cu, 0, N) if (ok[cu]) {
        printf("Yes\n");
        return;
    }
    
    printf("No\n");
}

Submission Info

Submission Time
Task C - ABland Yard
User hamayanhamayan
Language C++14 (GCC 5.4.1)
Score 900
Code Size 2600 Byte
Status AC
Exec Time 155 ms
Memory 30544 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 900 / 900
Status
AC × 4
AC × 59
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt
All 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 AC 5 ms 10752 KB
sample_02.txt AC 4 ms 10752 KB
sample_03.txt AC 4 ms 10752 KB
sample_04.txt AC 4 ms 10752 KB
test_01.txt AC 89 ms 25936 KB
test_02.txt AC 100 ms 26064 KB
test_03.txt AC 61 ms 19712 KB
test_04.txt AC 67 ms 23632 KB
test_05.txt AC 62 ms 21712 KB
test_06.txt AC 56 ms 19712 KB
test_07.txt AC 27 ms 15616 KB
test_08.txt AC 54 ms 19456 KB
test_09.txt AC 46 ms 17536 KB
test_10.txt AC 27 ms 15488 KB
test_11.txt AC 90 ms 25936 KB
test_12.txt AC 89 ms 26064 KB
test_13.txt AC 61 ms 19712 KB
test_14.txt AC 71 ms 23632 KB
test_15.txt AC 63 ms 21712 KB
test_16.txt AC 86 ms 19328 KB
test_17.txt AC 114 ms 19456 KB
test_18.txt AC 88 ms 19328 KB
test_19.txt AC 155 ms 23680 KB
test_20.txt AC 112 ms 19584 KB
test_21.txt AC 71 ms 20608 KB
test_22.txt AC 93 ms 25552 KB
test_23.txt AC 81 ms 21632 KB
test_24.txt AC 153 ms 28928 KB
test_25.txt AC 120 ms 25088 KB
test_26.txt AC 142 ms 30544 KB
test_27.txt AC 56 ms 20816 KB
test_28.txt AC 26 ms 16080 KB
test_29.txt AC 104 ms 24320 KB
test_30.txt AC 33 ms 15360 KB
test_31.txt AC 95 ms 25808 KB
test_32.txt AC 56 ms 21200 KB
test_33.txt AC 126 ms 29264 KB
test_34.txt AC 23 ms 14592 KB
test_35.txt AC 134 ms 30288 KB
test_36.txt AC 4 ms 10752 KB
test_37.txt AC 4 ms 10752 KB
test_38.txt AC 4 ms 10752 KB
test_39.txt AC 4 ms 10752 KB
test_40.txt AC 4 ms 10752 KB
test_41.txt AC 4 ms 10752 KB
test_42.txt AC 4 ms 10752 KB
test_43.txt AC 4 ms 10752 KB
test_44.txt AC 5 ms 10752 KB
test_45.txt AC 5 ms 10752 KB
test_46.txt AC 4 ms 10752 KB
test_47.txt AC 5 ms 10752 KB
test_48.txt AC 4 ms 10752 KB
test_49.txt AC 4 ms 10752 KB
test_50.txt AC 4 ms 10752 KB
test_51.txt AC 4 ms 10752 KB
test_52.txt AC 4 ms 10752 KB
test_53.txt AC 4 ms 10752 KB
test_54.txt AC 4 ms 10752 KB
test_55.txt AC 4 ms 10752 KB