50052023-04-09 00:35:06TomaSajtTom és Jerry 1 (80)cpp17Time limit exceeded 64/80577ms14768 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, -1);
  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] != -1)
        continue;
      dist_from_tom[v] = dist_from_tom[u] + 1;
      tq.push(v);
    }
  }

  auto do_attempt = [&](int jerry_start) {
    vector<int> dist(n + 1, -1);
    queue<int> jq;
    jq.push(jerry_start);
    dist[jerry_start] = 0;
    while (!jq.empty()) {
      int u = jq.front();
      jq.pop();
      for (auto v : graph[u]) {
        if (dist[v] != -1)
          continue;
        dist[v] = dist[u] + 1;
        if (dist_from_tom[v] != -1 && dist[v] >= dist_from_tom[v])
          continue;
        jq.push(v);
      }
    }
    return dist[goal] != -1;
  };
  while (attempts--) {
    int jerry_start;
    cin >> jerry_start;
    cout << (do_attempt(jerry_start) ? "IGEN" : "NEM") << endl;
  }
}
SubtaskSumTestVerdictTimeMemory
base64/80
1Accepted0/03ms1820 KiB
2Accepted0/04ms2320 KiB
3Accepted4/43ms2272 KiB
4Accepted4/43ms2360 KiB
5Accepted4/43ms2468 KiB
6Accepted4/43ms2680 KiB
7Accepted4/43ms3056 KiB
8Accepted4/43ms3204 KiB
9Accepted4/44ms3344 KiB
10Accepted4/44ms3768 KiB
11Accepted4/47ms4492 KiB
12Accepted4/49ms5492 KiB
13Accepted4/416ms6216 KiB
14Accepted4/427ms9036 KiB
15Accepted4/439ms9508 KiB
16Accepted4/445ms14768 KiB
17Accepted4/461ms13696 KiB
18Accepted4/439ms11444 KiB
19Time limit exceeded0/4550ms8212 KiB
20Time limit exceeded0/4560ms8152 KiB
21Time limit exceeded0/4577ms6836 KiB
22Time limit exceeded0/4537ms8228 KiB