QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#83891#1869. Power Station of ArtScintillaAC ✓248ms74576kbC++142.2kb2023-03-03 22:29:142023-03-03 22:29:17

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-03 22:29:17]
  • 评测
  • 测评结果:AC
  • 用时:248ms
  • 内存:74576kb
  • [2023-03-03 22:29:14]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb emplace_back
#define rep(i, s, e) for (int i = s; i <= e; ++i)
#define drep(i, s, e) for (int i = s; i >= e; --i)
#define file(a) freopen(#a".in", "r", stdin), freopen(#a".out", "w", stdout)
#define pv(a) cout << #a << " = " << a << endl
#define pa(a, l, r) cout << #a " : "; rep(_, l, r) cout << a[_] << ' '; cout << endl

using pii = pair <int, int>;

const int N = 1e6 + 10;

int read() {
  int x = 0, f = 1; char c = getchar();
  for (; c < '0' || c > '9'; c = getchar()) if (c == '-') f = -1;
  for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - 48;
  return x * f;
}

int n, m, col[N], a[N], b[N];
vector <int> e[N], con[N];
char s[N], t[N];

int fa[N];
int get(int u) { return u == fa[u] ? u : fa[u] = get(fa[u]); }
void merge(int u, int v) { fa[get(v)] = get(u); }

void solve() {
  n = read(), m = read();
  rep(i, 1, n) col[i] = -1, e[i].clear(), fa[i] = i, con[i].clear();
  rep(i, 1, m) {
    int u = read(), v = read();
    e[u].pb(v), e[v].pb(u), merge(u, v);
  }
  rep(i, 1, n) a[i] = read();
  scanf("%s", s + 1);
  rep(i, 1, n) b[i] = read();
  scanf("%s", t + 1);
  rep(i, 1, n) con[get(i)].pb(i);
  rep(i, 1, n) if (get(i) == i) {
    col[i] = 0;
    function <bool(int)> dfs = [&](int u) {
      for (int v : e[u]) {
        if (~col[v]) {
          if (col[u] == col[v]) return false;
        }
        else {
          col[v] = !col[u];
          if (!dfs(v)) return false;
        }
      }
      return true;
    } ;
    if (dfs(i)) {
      multiset <pii> x, y;
      for (auto it : con[i]) {
        x.insert(mp(a[it], col[it] ^ (s[it] == 'B')));
        y.insert(mp(b[it], col[it] ^ (t[it] == 'B')));
      }
      if (x != y) return printf("NO\n"), void();
    }
    else {
      int cx = 0, cy = 0;
      multiset <int> x, y;
      for (auto it : con[i]) {
        cx += s[it] == 'R', cy += t[it] == 'R';
        x.insert(a[it]), y.insert(b[it]);
      }
      if ((cx & 1) != (cy & 1)) return printf("NO\n"), void();
      if (x != y) return printf("NO\n"), void();
    }
  }
  printf("YES\n");
}

int main() {
  for (int tc = read(); tc; -- tc) {
    solve();
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 8ms
memory: 50580kb

input:

3
2 1
1 2
3 4
RR
4 3
BB
3 2
1 2
2 3
1 1 1
RBR
1 1 1
BBB
3 3
1 2
2 3
3 1
1 1 1
RBR
1 1 1
BBB

output:

YES
NO
YES

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 248ms
memory: 74576kb

input:

25054
5 10
4 5
4 2
4 3
4 1
5 2
5 3
5 1
2 3
2 1
3 1
12 2 9 10 7
RRRBB
10 2 9 7 12
RRBRB
1 0
4
R
4
R
8 4
4 3
1 5
8 5
6 5
7 2 11 10 9 6 3 5
RBRBBRBR
7 2 10 11 6 5 3 9
RBRBBRBR
7 4
7 2
5 1
5 6
5 4
12 5 9 14 5 12 12
RRBRBRR
14 12 9 5 12 12 5
RBBRBRB
10 1
4 6
5 3 2 9 7 3 11 11 6 8
RRRBRRBBBR
5 3 2 3 7 9 1...

output:

YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
NO
YES
NO
NO
YES
YES
YES
NO
YES
NO
YES
YES
NO
YES
YES
NO
YES
NO
YES
YES
YES
YES
NO
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
NO
YES
NO
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
NO
YES
NO
NO...

result:

ok 25054 lines