QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#396738#7202. Easy When You Know HowftiaschWA 1ms3616kbC++201.6kb2024-04-23 09:13:572024-04-23 09:13:57

Judging History

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

  • [2024-04-23 09:13:57]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3616kb
  • [2024-04-23 09:13:57]
  • 提交

answer

#include <bits/stdc++.h>
#include <experimental/type_traits>

// {{{ boilerplate

class Dsu : public std::vector<int> {
public:
  explicit Dsu(int n) : std::vector<int>(n, -1) {}

  int find(int u) {
    if ((*this)[u] == -1) {
      return u;
    }
    if ((*this)[u] != u) {
      (*this)[u] = find((*this)[u]);
    }
    return (*this)[u];
  }

  bool merge(int a, int b) {
    if (find(a) == find(b)) {
      return false;
    }
    (*this)[find(a)] = find(b);
    return true;
  }
};

// }}}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  std::cout.tie(0);
  int n, Q;
  while (std::cin >> n >> Q) {
    std::vector<std::tuple<int, int, int>> queries(Q);
    std::vector<int> count(n + 1);
    for (int i = 0, x, y, l; i < Q; i++) {
      queries[i] = {x - 1, y - 1, l};
      count[l]++;
    }
    for (int i = 1; i <= n; i++) {
      count[i] += count[i - 1];
    }
    std::vector<std::pair<int, int>> queue(Q);
    for (auto [x, y, l] : queries) {
      queue[--count[l]] = {x, y};
    }
    Dsu dsu(n);
    int rear{n}, components{n};
    for (int l = n; l >= 1; l--) {
      auto head = count[l];
      for (int i = rear; i-- > head;) {
        auto [x, y] = queue[i];
        if (dsu.merge(x, y)) {
          components--;
          queue[i++] = queue[head];
          queue[head++] = {
              x + 1,
              y + 1,
          };
        }
      }
      rear = head;
    }
    int result{1};
    for (int _ = 0; _ < components; _++) {
      result = 26LL * result % 1'000'000'007;
    }
    std::cout << result << '\n';
  }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3616kb

input:

5 5
1 1 1
2 2 1
3 3 1
4 4 1
5 5 1
8 3
1 4 3
3 4 1
4 6 3

output:

11881376
26
26
676
17576
26
456976
11881376
26
17576
456976
17576
26
308915776

result:

wrong answer 2nd words differ - expected: '676', found: '26'