Submission #776219

# Submission time Handle Problem Language Result Execution time Memory
776219 2023-07-07T13:08:43 Z tch1cherin From Hacks to Snitches (BOI21_watchmen) C++17
0 / 100
882 ms 88912 KB
#include <bits/stdc++.h>
using namespace std;

void solve() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> g(n);
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  vector<pair<int, int>> used_V(n, {-1, -1});
  map<pair<int, int>, pair<int, int>> used_E;
  int k;
  cin >> k;
  for (int j = 0; j < k; j++) {
    int L;
    cin >> L;
    vector<int> cycle(L);
    for (int &v : cycle) {
      cin >> v;
      v--; 
    }
    for (int i = 0; i < L; i++) {
      used_V[cycle[i]] = {i, L};
      int x = cycle[i], y = cycle[i + 1 < L ? i + 1 : 0];
      used_E[{x, y}] = used_E[{y, x}] = {i, L};
    }
  }
  vector d(n, vector<int>(201, INT_MAX));
  queue<pair<int, int>> q;
  q.push({0, 0});
  d[0][0] = 0;
  while (!q.empty()) {
    auto [u, r] = q.front();
    q.pop();
    bool can_stay = true; 
    for (int v : g[u]) {
      if (used_E.count({u, v}) && d[u][r] % used_E[{u, v}].second == used_E[{u, v}].first) {
        can_stay = false;
        continue;
      }
      if (used_V[v].first != -1 && (d[u][r] + 1) % used_V[v].second == used_V[v].first) {
        continue;
      }
      if (d[v][0] == INT_MAX) {
        d[v][0] = d[u][r] + 1;
        q.push({v, 0}); 
      }
    }
    if (can_stay && r < 200) {
      d[u][r + 1] = d[u][r] + 1;
      q.push({u, r + 1});  
    }
  }
  cout << d[n - 1][0] << "\n";
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  solve();
}
# Verdict Execution time Memory Grader output
1 Correct 394 ms 1504 KB Output is correct
2 Incorrect 882 ms 88912 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 384 ms 1492 KB Output is correct
2 Incorrect 851 ms 88904 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 384 ms 1492 KB Output is correct
2 Incorrect 851 ms 88904 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 384 ms 1492 KB Output is correct
2 Incorrect 851 ms 88904 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 394 ms 1504 KB Output is correct
2 Incorrect 882 ms 88912 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 394 ms 1504 KB Output is correct
2 Incorrect 882 ms 88912 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 394 ms 1504 KB Output is correct
2 Incorrect 882 ms 88912 KB Output isn't correct
3 Halted 0 ms 0 KB -