50072023-04-09 01:05:07TomaSajtTom és Jerry 1 (80)cpp17Elfogadva 80/80224ms17912 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
  cin.tie(0), ios::sync_with_stdio(0);
  int n, m, tom_start, attempts, goal;
  cin >> n >> m >> tom_start >> attempts >> goal;
  vector<vector<int>> graph(n + 1), tom_graph(n + 1);
  while (m--) {
    int u, v, s;
    cin >> u >> v >> s;
    graph[u].push_back(v);
    graph[v].push_back(u);
    if (s == 2) {
      tom_graph[u].push_back(v);
      tom_graph[v].push_back(u);
    }
  }

  vector<int> dist_from_tom(n + 1, INT_MAX);
  queue<int> tq;
  tq.push(tom_start);
  dist_from_tom[tom_start] = 0;
  while (!tq.empty()) {
    int u = tq.front();
    tq.pop();
    for (auto v : tom_graph[u]) {
      if (dist_from_tom[v] != INT_MAX)
        continue;
      dist_from_tom[v] = dist_from_tom[u] + 1;
      tq.push(v);
    }
  }
  vector<bool> can_jerry_start_at(n + 1);
  can_jerry_start_at[goal] = true;
  priority_queue<array<int, 2>> pq;
  pq.push({dist_from_tom[goal], goal});
  while (!pq.empty()) {
    auto [u_t, u] = pq.top();
    pq.pop();
    if (u_t < 0)
      continue;
    can_jerry_start_at[u] = true;
    for (int v : graph[u]) {
      if (can_jerry_start_at[v])
        continue;
      // jerry should be at position `v`
      // not later than `T = dist_from_tom[v] - 1` to avoid getting caught
      // not later than `T = u_t - 1` so that they can step to `u` right after
      pq.push({min(dist_from_tom[v] - 1, u_t - 1), v});
    }
  }

  while (attempts--) {
    int jerry_start;
    cin >> jerry_start;
    cout << (can_jerry_start_at[jerry_start] ? "IGEN" : "NEM") << endl;
  }
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base80/80
1Elfogadva0/03ms1992 KiB
2Elfogadva0/04ms2596 KiB
3Elfogadva4/43ms2456 KiB
4Elfogadva4/43ms2664 KiB
5Elfogadva4/43ms2672 KiB
6Elfogadva4/43ms2804 KiB
7Elfogadva4/43ms3064 KiB
8Elfogadva4/44ms3388 KiB
9Elfogadva4/44ms3784 KiB
10Elfogadva4/44ms4024 KiB
11Elfogadva4/416ms4996 KiB
12Elfogadva4/48ms5564 KiB
13Elfogadva4/428ms7304 KiB
14Elfogadva4/459ms10228 KiB
15Elfogadva4/4224ms17720 KiB
16Elfogadva4/441ms14740 KiB
17Elfogadva4/461ms14644 KiB
18Elfogadva4/482ms12956 KiB
19Elfogadva4/464ms13780 KiB
20Elfogadva4/465ms13496 KiB
21Elfogadva4/450ms11484 KiB
22Elfogadva4/4157ms17912 KiB