Submission #588609

# Submission time Handle Problem Language Result Execution time Memory
588609 2022-07-03T16:45:11 Z MilosMilutinovic Tropical Garden (IOI11_garden) C++14
0 / 100
1 ms 852 KB
/**
 *    author:  wxhtzdy
 *    created: 03.07.2022 18:28:39
**/
#include "garden.h"
#include "gardenlib.h"

#include <bits/stdc++.h>

using namespace std;

void count_routes(int n, int m, int p, int r[][2], int q, int k[]) {
  vector<vector<pair<int, int>>> e(n);
  for (int i = m - 1; i >= 0; i--) {
    if ((int) e[r[i][0]].size() < 2) {
      e[r[i][0]].emplace_back(i, r[i][1]);
    }
    if ((int) e[r[i][1]].size() < 2) {
      e[r[i][1]].emplace_back(i, r[i][0]);
    }
  }
  for (int i = 0; i < n; i++) {
    if ((int) e[i].size() == 1) {
      e[i].push_back(e[i][0]);
    }
  }
  vector<vector<int>> g(2 * n);
  function<void(int, int)> Add = [&](int v, int u) {
    g[v].push_back(u);
  };
  for (int i = 0; i < n; i++) {
    if (e[i][0].first == e[e[i][0].first][0].first) {
      Add(i * 2, e[i][0].second * 2 + 1);
    } else {
      Add(i * 2, e[i][0].second * 2);
    }          
    if (e[i][1].first == e[e[i][1].first][0].first) {
      Add(i * 2 + 1, e[i][0].second * 2 + 1);
    } else {
      Add(i * 2 + 1, e[i][1].second * 2);
    }
  }
  const int L = 32;
  vector<vector<int>> jump(n, vector<int>(L));
  for (int i = 0; i < n; i++) {
    jump[i][0] = g[i * 2][0];    
  }
  for (int j = 1; j < L; j++) {
    for (int i = 0; i < n; i++) {
      jump[i][j] = jump[jump[i][j - 1]][j - 1];
    }
  }
  for (int i = 0; i < q; i++) {
    int cnt = 0;
    for (int j = 0; j < n; j++) {
      int x = j;
      for (int l = L - 1; l >= 0; l--) {
        if (k[i] >> l & 1) {
          x = jump[x][l];
        }
      }
      if (x == p) {
        cnt += 1;
      }
    }            
    answer(cnt);
  }
}
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 852 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 852 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 852 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -