Submission #3210010

Source Code Expand

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

#define NDEBUG
#include <cassert>

typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair


bool solve(int N, int M, string& s, vi& a, vi& b) {
    vvi next(N);
    vi a_side(N,0), b_side(N,0);

    rep(i,M) {
        int u = a[i], v = b[i];
        bool cu = (s[u] == 'A'), cv = (s[v] == 'A');
        if (cv) ++a_side[u];
        else    ++b_side[u];
        next[u].pb(v);

        if (u != v) {
            if (cu) ++a_side[v];
            else    ++b_side[v];
            next[v].pb(u);
        }
    }

    queue<int> q;
    vector<bool> visited(N, false);
    int alive = N;



    rep(i,N){
        if (a_side[i]==0 || b_side[i]==0) {
            q.push(i);
        }
    }
    while (!q.empty()){
        int u = q.front(); q.pop();
        if (visited[u]) continue;

        bool cu = (s[u] == 'A');

        visited[u] = true;
        --alive;

        for (int v: next[u]) {
            if (visited[v]) continue;
            if (cu) --a_side[v];
            else    --b_side[v];
            if (a_side[v]==0 || b_side[v]==0) {
                q.push(v);
            }
        }
    }
    return alive > 0;
}

int main() {
    int N, M; cin >> N >> M;
    string s; cin >> s;
    vi a(M), b(M);
    rep(i,M) { scanf("%d %d", &a[i], &b[i]); --a[i]; --b[i]; }
    cout << (solve(N,M,s,a,b) ? "Yes":"No") << endl;
    return 0;
}

Submission Info

Submission Time
Task C - ABland Yard
User naoya_t
Language C++14 (GCC 5.4.1)
Score 900
Code Size 2462 Byte
Status
Exec Time 91 ms
Memory 13700 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:93:44: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     rep(i,M) { scanf("%d %d", &a[i], &b[i]); --a[i]; --b[i]; }
                                            ^

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 1 ms 256 KB
sample_02.txt 1 ms 256 KB
sample_03.txt 1 ms 256 KB
sample_04.txt 1 ms 256 KB
test_01.txt 66 ms 10756 KB
test_02.txt 66 ms 10884 KB
test_03.txt 42 ms 6528 KB
test_04.txt 55 ms 9216 KB
test_05.txt 53 ms 7936 KB
test_06.txt 37 ms 6400 KB
test_07.txt 19 ms 3584 KB
test_08.txt 35 ms 6272 KB
test_09.txt 31 ms 4992 KB
test_10.txt 19 ms 3456 KB
test_11.txt 63 ms 10756 KB
test_12.txt 65 ms 10884 KB
test_13.txt 37 ms 6528 KB
test_14.txt 60 ms 9216 KB
test_15.txt 53 ms 7936 KB
test_16.txt 19 ms 2176 KB
test_17.txt 25 ms 3328 KB
test_18.txt 19 ms 2432 KB
test_19.txt 32 ms 3584 KB
test_20.txt 26 ms 3712 KB
test_21.txt 30 ms 3456 KB
test_22.txt 68 ms 10244 KB
test_23.txt 51 ms 7296 KB
test_24.txt 70 ms 8448 KB
test_25.txt 51 ms 6016 KB
test_26.txt 87 ms 12548 KB
test_27.txt 48 ms 8704 KB
test_28.txt 27 ms 6912 KB
test_29.txt 56 ms 7296 KB
test_30.txt 14 ms 1792 KB
test_31.txt 68 ms 11396 KB
test_32.txt 49 ms 10116 KB
test_33.txt 73 ms 9728 KB
test_34.txt 17 ms 3200 KB
test_35.txt 91 ms 13700 KB
test_36.txt 1 ms 256 KB
test_37.txt 1 ms 256 KB
test_38.txt 1 ms 256 KB
test_39.txt 1 ms 256 KB
test_40.txt 1 ms 256 KB
test_41.txt 1 ms 256 KB
test_42.txt 1 ms 256 KB
test_43.txt 1 ms 256 KB
test_44.txt 1 ms 256 KB
test_45.txt 1 ms 256 KB
test_46.txt 1 ms 256 KB
test_47.txt 1 ms 256 KB
test_48.txt 1 ms 256 KB
test_49.txt 1 ms 256 KB
test_50.txt 1 ms 256 KB
test_51.txt 1 ms 256 KB
test_52.txt 1 ms 256 KB
test_53.txt 1 ms 256 KB
test_54.txt 1 ms 256 KB
test_55.txt 1 ms 256 KB