Submission #964142

# Submission time Handle Problem Language Result Execution time Memory
964142 2024-04-16T11:08:51 Z LucaLucaM Constellation 3 (JOI20_constellation3) C++17
0 / 100
2 ms 6492 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
#include <cstring>
#include <queue>
#warning That's not AS, that's my AS

typedef long long ll;

const int NMAX = 2e5;
const int DMAX = 40;

int L;

int mult[NMAX + 1][DMAX + 1];

std::vector<int> g[NMAX + 1];
int parent[NMAX + 1];
int Time[NMAX + 1];
int timer;

void bfs() {
  std::queue<int> q;
  q.push(1);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    Time[u] = ++timer;
    std::vector<int> newG;
    for (const auto &v : g[u]) {
      if (!Time[v]) {
        parent[v] = u;
        newG.push_back(v);
        q.push(v);
      }
    }
    g[u] = newG;
  }
}

int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);
  std::cout.tie(0);

  int n;
  std::cin >> n >> L;

  for (int i = 1; i < n; i++) {
    int u, v;
    std::cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }

  bfs();

  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= DMAX; j++) {
      mult[i][j] = 1;
    }
  }

  for (int i = 1; i <= n; i++) {
    int h;
    std::cin >> h;
    mult[i][0] = h;
  }

  int q;
  std::cin >> q;

  while (q--) {
    int type;
    std::cin >> type;
    if (type == 1) {
      int u, d, h;
      std::cin >> u >> d >> h;
      std::vector<std::pair<int, int>> ancestors;
      int v = u;
      while (d >= 0) {
        mult[v][d] = (ll) mult[v][d] * h % L;
        d--;
        if (d >= 0) {
          mult[v][d] = (ll) mult[v][d] * h % L;
        }
        if (v != 1) {
          v = parent[v];
        } else {
          d--;
        }
      }
    } else {
      int u;
      std::cin >> u;
      std::vector<std::pair<int, int>> ancestors;
      int v = u;
      int answer = 1;
      for (int i = 0; i <= DMAX && v != 0; i++) {
        answer = (ll) answer * mult[v][i] % L;
        v = parent[v];
      }
      std::cout << answer << '\n';
    }
  }

  return 0;
}

Compilation message

constellation3.cpp:7:2: warning: #warning That's not AS, that's my AS [-Wcpp]
    7 | #warning That's not AS, that's my AS
      |  ^~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 6492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 6492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 6492 KB Output isn't correct
2 Halted 0 ms 0 KB -