50062023-04-09 01:04:43TomaSajtTom és Jerry 1 (80)cpp17Wrong answer 0/80560ms14468 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();
    cout << u << endl;
    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;
  }
}
SubtaskSumTestVerdictTimeMemory
base0/80
1Wrong answer0/03ms1956 KiB
2Wrong answer0/016ms2420 KiB
3Wrong answer0/43ms2336 KiB
4Wrong answer0/43ms2276 KiB
5Wrong answer0/43ms2344 KiB
6Wrong answer0/43ms2564 KiB
7Wrong answer0/46ms2928 KiB
8Wrong answer0/48ms3160 KiB
9Wrong answer0/417ms3464 KiB
10Wrong answer0/44ms3632 KiB
11Wrong answer0/4101ms4972 KiB
12Wrong answer0/413ms5368 KiB
13Wrong answer0/4158ms6912 KiB
14Wrong answer0/4377ms9888 KiB
15Time limit exceeded0/4560ms9872 KiB
16Wrong answer0/4107ms14468 KiB
17Wrong answer0/4109ms14384 KiB
18Wrong answer0/4272ms13008 KiB
19Wrong answer0/4149ms13636 KiB
20Wrong answer0/4114ms13396 KiB
21Wrong answer0/4104ms11420 KiB
22Time limit exceeded0/4559ms10560 KiB