QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#833740#2679. 校园旅行nhuang685100 ✓623ms22488kbC++233.4kb2024-12-27 01:44:362024-12-27 01:44:37

Judging History

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

  • [2024-12-27 01:44:37]
  • 评测
  • 测评结果:100
  • 用时:623ms
  • 内存:22488kb
  • [2024-12-27 01:44:36]
  • 提交

answer

/**
 * @author n685
 * @date 2024-12-26 11:50:21
 */
#include "bits/stdc++.h"

#ifdef LOCAL
#include "dd/debug.h"
#else
#define dbg(...) 42
#define dbg_proj(...) 420
#define dbg_rproj(...) 420420
void nline() {}
void bar() {}
void start_clock() {}
void end_clock() {}
#endif

namespace rs = std::ranges;
namespace rv = std::views;

using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

int main() {
#ifndef LOCAL
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
#endif

  int n, m, q;
  std::cin >> n >> m >> q;

  std::vector<bool> lb(n);
  for (int i = 0; i < n; ++i) {
    char c;
    std::cin >> c;
    lb[i] = c == '1';
  }

  std::vector<std::pair<int, int>> diff(n);
  std::vector<std::vector<int>> same(n);
  for (int i = 0; i < m; ++i) {
    int u, v;
    std::cin >> u >> v;
    --u;
    --v;
    if (lb[u] == lb[v]) {
      same[u].push_back(v);
      same[v].push_back(u);
    } else {
      diff.emplace_back(u, v);
    }
  }

  std::vector<std::vector<int>> adj(n);
  std::vector<bool> vis(n);
  std::vector<int> cc(n, -1), clr(n);
  std::vector<bool> bp(n, true);
  auto dfs = [&](auto&& self, int node, int par) -> bool {
    bool g = true;
    for (int i : same[node]) {
      if (i == par) {
        continue;
      }
      if (vis[i]) {
        if (clr[node] == clr[i]) {
          g = false;
        }
        continue;
      }
      adj[node].push_back(i);
      adj[i].push_back(node);
      cc[i] = cc[node];
      vis[i] = true;
      clr[i] = !clr[node];
      if (!self(self, i, node)) {
        g = false;
      }
    }
    return g;
  };
  for (int i = 0, cnt = 0; i < n; ++i) {
    if (vis[i]) {
      continue;
    }
    vis[i] = true;
    cc[i] = cnt++;
    if (!dfs(dfs, i, -1)) {
      adj[i].push_back(i);
      bp[cc[i]] = false;
    }
  }
  vis.assign(n, false);
  std::vector<std::vector<std::pair<int, int>>> dadj(n);
  for (int i = 0; i < std::ssize(diff); ++i) {
    dadj[diff[i].first].emplace_back(i, diff[i].second);
    dadj[diff[i].second].emplace_back(i, diff[i].first);
  }
  auto dfs2 = [&](auto&& self, int node, int par) -> void {
    for (auto [t, i] : dadj[node]) {
      if (i == par) {
        continue;
      }
      if (vis[i]) {
        continue;
      }
      vis[i] = true;
      adj[diff[t].first].push_back(diff[t].second);
      adj[diff[t].second].push_back(diff[t].first);
      self(self, i, node);
    }
  };
  for (int i = 0; i < n; ++i) {
    if (vis[i]) {
      continue;
    }
    vis[i] = true;
    dfs2(dfs2, i, -1);
  }
  for (int i = 0; i < n; ++i) {
    dbg(i, adj[i]);
  }

  std::vector f(n, std::vector<bool>(n));
  std::queue<std::pair<int, int>> qq;
  for (int i = 0; i < n; ++i) {
    f[i][i] = true;
    qq.emplace(i, i);
    for (int j : adj[i]) {
      if (lb[i] == lb[j]) {
        f[i][j] = true;
        qq.emplace(i, j);
      }
    }
  }
  while (!qq.empty()) {
    auto [i, j] = qq.front();
    qq.pop();
    for (int u : adj[i]) {
      for (int v : adj[j]) {
        if (!f[u][v] && lb[u] == lb[v]) {
          f[u][v] = true;
          qq.emplace(u, v);
        }
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    dbg(i, f[i]);
  }

  while (q--) {
    int u, v;
    std::cin >> u >> v;
    --u;
    --v;
    std::cout << (f[u][v] ? "YES" : "NO") << '\n';
  }
}


詳細信息


Pretests


Final Tests

Test #1:

score: 10
Accepted
time: 450ms
memory: 22488kb

input:

3000 10000 100000
110000100010110011101010100100001001000101110111011011101111111001100001011010101011001010100001011111001010100011101100101111110001011100000011000010101101010110110111001011110100100011000110101011000110110000011010101100000101111011010001110010011100010111110100010000011001001101...

output:

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

result:

ok 100000 lines

Test #2:

score: 10
Accepted
time: 190ms
memory: 6116kb

input:

3000 9265 100000
0111101100111000110010101001111100011111111011000111101101010000011110010100011011000011100001111011010001010110100011001111011010101111011101101101111010001110101010000000111110011000101110111011001101000010111101011011000110101010001110011111101100111011010001101110011000001010001...

output:

NO
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES
NO
NO
YES
YES
YES
YES
YES
YES
NO
YES
NO
YES
YES
YES
YES
YES
YES
YES
NO
NO
YES
YES
YES
YES
YES
NO
YES
YES
NO
YES
YES
YES
NO
YES
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
NO
YES
YES
YES
NO
YES
YES
NO
Y...

result:

ok 100000 lines

Test #3:

score: 10
Accepted
time: 181ms
memory: 6048kb

input:

3000 10000 100000
111101111111010000110001010110001111111011000110100101100000111110000110011010010001100110110011100010011100011001000111110100101011010001100010011010100001011101001000110000110111000100111010010001111111011100111000011110110111011111100111100101011110011111111001100011100100111111...

output:

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

result:

ok 100000 lines

Test #4:

score: 10
Accepted
time: 83ms
memory: 7292kb

input:

3000 50000 100000
010100100001111000100101000001011111100010100010101010100110100010110010110000011010100001001110000101100000001101100010001001011001110010101011011011011000101111111100011010000001110100001001010111011111011001100011111000011000011101001100010111000111010001100010100111110010001011...

output:

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

result:

ok 100000 lines

Test #5:

score: 10
Accepted
time: 156ms
memory: 6824kb

input:

3000 50000 100000
001000000001001110011111011010101001000101110110000110011100101010010011101000110010111010001010110001011000111100111101100000111000101111011010000101101111110010000111011100100001111000000001111110000110100011100010110111100101000110111011000001111100000111101000001101001110101010...

output:

YES
YES
NO
NO
NO
YES
YES
YES
YES
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
YES
YES
YES
YES
NO
NO
YES
NO
NO
YES
NO
NO
NO
YES
YES
NO
YES
YES
YES
NO
NO
NO
YES
YES
NO
YES
NO
NO
NO
YES
YES
NO
YES
YES
YES
NO
YES
YES
YES
NO
YES
YES
YES
YES
YES
NO
NO
YES
NO
YES
YES
YES
YES
NO
YES
NO
YES
YES
YES
YES
YES
NO
NO
YES
YES
N...

result:

ok 100000 lines

Test #6:

score: 10
Accepted
time: 182ms
memory: 6588kb

input:

3000 50000 100000
110011011010100101101101100111100110011110101011111001101011110110101010101110000111111001000001100011100011001100010011011101101011010000100101000110110111001111111001111011001110101110001110110100010000111100000101101111000001111010011101100111111110010001011011101001011110100111...

output:

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

result:

ok 100000 lines

Test #7:

score: 10
Accepted
time: 210ms
memory: 6776kb

input:

3000 50000 100000
111011101011110010111011011110110011101010100000101111100100011001000010110001010000101111010110110000110111100011110101000100001100100100011011100010010010101111100010000010011101001101000001111011001011101001101111100001100001101100100110011010001101111101100111001010111100100011...

output:

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

result:

ok 100000 lines

Test #8:

score: 10
Accepted
time: 623ms
memory: 15952kb

input:

5000 361135 100000
00000011101011100011110101101001100110010001101001100101101001111010101110111010111100110000010110011100100100011100101010011011000011111010110111011010100001010011001110001111010001110010000000100110101111000110111001111011110111100000110011101101000110001111001101000111010011111...

output:

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

result:

ok 100000 lines

Test #9:

score: 10
Accepted
time: 610ms
memory: 18440kb

input:

5000 500000 100000
10101100011011001010110100000010100001110111001010100100100100000010010001001011001110001010110000000010110011010101010101001011110111001001100001001011011001001010110101111001101111110010001101010010101001101100110100001010000110001100011001001110110110100100100101111101000001111...

output:

NO
NO
NO
YES
NO
YES
NO
YES
YES
YES
YES
NO
YES
YES
YES
YES
NO
NO
YES
YES
YES
YES
YES
NO
YES
NO
YES
YES
NO
YES
YES
NO
YES
NO
YES
YES
YES
NO
NO
YES
YES
NO
YES
NO
NO
YES
YES
YES
YES
NO
NO
NO
NO
NO
YES
NO
YES
NO
NO
NO
YES
YES
YES
YES
YES
YES
YES
NO
NO
YES
YES
NO
YES
YES
NO
NO
YES
NO
YES
NO
NO
YES
NO
NO
Y...

result:

ok 100000 lines

Test #10:

score: 10
Accepted
time: 621ms
memory: 18436kb

input:

5000 500000 100000
11011101110101000011000010101011101000000011001111101011111001010111000101110000011100100101011001011011011001011111011101000111010101100000000110001010011000010101010100000101101001100101010001111011001100111001001001011000001000100111011110101011011100010011100001101000001010110...

output:

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

result:

ok 100000 lines