█████████ ████ ███░░░░░███ ░░███ ███ ░░░ ██████ ███████ ██████ ██████ ░███ ███░░███ ███░░███ ███░░███ ███░░███ ░███ ░███ ░███░███ ░███ ░███████ ░███ ░███ ░░███ ███░███ ░███░███ ░███ ░███░░░ ░███ ░███ ░░█████████ ░░██████ ░░████████░░██████ ░░██████ ░░░░░░░░░ ░░░░░░ ░░░░░░░░ ░░░░░░ ░░░░░░

Envío 6010

Problema 0x53 - Encontrar ciclos en un grafo dirigido

  • Autor: jarangolp
  • Fecha: 2022-05-02 13:27:16 UTC (Hace más de 2 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.022 s 6 KBi
#2
Incorrecto
0.023 s 6 KBi
#3
Error en tiempo de ejecución (NZEC)
Exited with error status 1
/box/script.js:6
  for (let i = 0; i < adj[index].length; i++) {
                                 ^

TypeError: Cannot read property 'length' of undefined
    at dfs (/box/script.js:6:34)
    at ReadStream.<anonymous> (/box/script.js:24:20)
    at ReadStream.emit (events.js:210:5)
    at addChunk (_stream_readable.js:309:12)
    at readableAddChunk (_stream_readable.js:290:11)
    at ReadStream.Readable.push (_stream_readable.js:224:10)
    at internal/fs/streams.js:191:12
    at FSReqCallback.wrapper [as oncomplete] (fs.js:470:5)
0.023 s 6 KBi
#4
Incorrecto
0.022 s 6 KBi
#5
Incorrecto
0.024 s 6 KBi
#6
Error en tiempo de ejecución (NZEC)
Exited with error status 1
/box/script.js:6
  for (let i = 0; i < adj[index].length; i++) {
                                 ^

TypeError: Cannot read property 'length' of undefined
    at dfs (/box/script.js:6:34)
    at ReadStream.<anonymous> (/box/script.js:24:20)
    at ReadStream.emit (events.js:210:5)
    at addChunk (_stream_readable.js:309:12)
    at readableAddChunk (_stream_readable.js:290:11)
    at ReadStream.Readable.push (_stream_readable.js:224:10)
    at internal/fs/streams.js:191:12
    at FSReqCallback.wrapper [as oncomplete] (fs.js:470:5)
0.072 s 33 KBi
#7
Incorrecto
0.083 s 6 KBi
#8
Incorrecto
0.023 s 6 KBi
#9
Incorrecto
0.025 s 6 KBi
#10
Correcto
0.082 s 7 KBi
#11
Error en tiempo de ejecución (NZEC)
Exited with error status 1
/box/script.js:6
  for (let i = 0; i < adj[index].length; i++) {
                                 ^

TypeError: Cannot read property 'length' of undefined
    at dfs (/box/script.js:6:34)
    at ReadStream.<anonymous> (/box/script.js:24:20)
    at ReadStream.emit (events.js:210:5)
    at addChunk (_stream_readable.js:309:12)
    at readableAddChunk (_stream_readable.js:290:11)
    at ReadStream.Readable.push (_stream_readable.js:224:10)
    at internal/fs/streams.js:191:12
    at FSReqCallback.wrapper [as oncomplete] (fs.js:470:5)
0.071 s 6 KBi
#12
Error en tiempo de ejecución (NZEC)
Exited with error status 1
/box/script.js:6
  for (let i = 0; i < adj[index].length; i++) {
                                 ^

TypeError: Cannot read property 'length' of undefined
    at dfs (/box/script.js:6:34)
    at ReadStream.<anonymous> (/box/script.js:24:20)
    at ReadStream.emit (events.js:210:5)
    at addChunk (_stream_readable.js:309:12)
    at readableAddChunk (_stream_readable.js:290:11)
    at ReadStream.Readable.push (_stream_readable.js:224:10)
    at internal/fs/streams.js:191:12
    at FSReqCallback.wrapper [as oncomplete] (fs.js:470:5)
0.021 s 6 KBi
#13
Error en tiempo de ejecución (NZEC)
Exited with error status 1
/box/script.js:6
  for (let i = 0; i < adj[index].length; i++) {
                                 ^

TypeError: Cannot read property 'length' of undefined
    at dfs (/box/script.js:6:34)
    at ReadStream.<anonymous> (/box/script.js:24:20)
    at ReadStream.emit (events.js:210:5)
    at addChunk (_stream_readable.js:309:12)
    at readableAddChunk (_stream_readable.js:290:11)
    at ReadStream.Readable.push (_stream_readable.js:224:10)
    at internal/fs/streams.js:191:12
    at FSReqCallback.wrapper [as oncomplete] (fs.js:470:5)
0.019 s 7 KBi
#14
Error en tiempo de ejecución (NZEC)
Exited with error status 1
/box/script.js:6
  for (let i = 0; i < adj[index].length; i++) {
                                 ^

TypeError: Cannot read property 'length' of undefined
    at dfs (/box/script.js:6:34)
    at ReadStream.<anonymous> (/box/script.js:24:20)
    at ReadStream.emit (events.js:210:5)
    at addChunk (_stream_readable.js:309:12)
    at readableAddChunk (_stream_readable.js:290:11)
    at ReadStream.Readable.push (_stream_readable.js:224:10)
    at internal/fs/streams.js:191:12
    at FSReqCallback.wrapper [as oncomplete] (fs.js:470:5)
0.053 s 6 KBi
#15
Error en tiempo de ejecución (NZEC)
Exited with error status 1
/box/script.js:6
  for (let i = 0; i < adj[index].length; i++) {
                                 ^

TypeError: Cannot read property 'length' of undefined
    at dfs (/box/script.js:6:34)
    at ReadStream.<anonymous> (/box/script.js:24:20)
    at ReadStream.emit (events.js:210:5)
    at addChunk (_stream_readable.js:309:12)
    at readableAddChunk (_stream_readable.js:290:11)
    at ReadStream.Readable.push (_stream_readable.js:224:10)
    at internal/fs/streams.js:191:12
    at FSReqCallback.wrapper [as oncomplete] (fs.js:470:5)
0.024 s 6 KBi
#16
Correcto
0.024 s 7 KBi
#17
Correcto
0.07 s 7 KBi
#18
Error en tiempo de ejecución (NZEC)
Exited with error status 1
/box/script.js:6
  for (let i = 0; i < adj[index].length; i++) {
                                 ^

TypeError: Cannot read property 'length' of undefined
    at dfs (/box/script.js:6:34)
    at ReadStream.<anonymous> (/box/script.js:24:20)
    at ReadStream.emit (events.js:210:5)
    at addChunk (_stream_readable.js:309:12)
    at readableAddChunk (_stream_readable.js:290:11)
    at ReadStream.Readable.push (_stream_readable.js:224:10)
    at internal/fs/streams.js:191:12
    at FSReqCallback.wrapper [as oncomplete] (fs.js:470:5)
0.049 s 7 KBi
#19
Incorrecto
0.051 s 7 KBi
#20
Incorrecto
0.032 s 7 KBi
#21
Incorrecto
0.022 s 6 KBi
#22
Error en tiempo de ejecución (NZEC)
Exited with error status 1
/box/script.js:6
  for (let i = 0; i < adj[index].length; i++) {
                                 ^

TypeError: Cannot read property 'length' of undefined
    at dfs (/box/script.js:6:34)
    at ReadStream.<anonymous> (/box/script.js:24:20)
    at ReadStream.emit (events.js:210:5)
    at addChunk (_stream_readable.js:309:12)
    at readableAddChunk (_stream_readable.js:290:11)
    at ReadStream.Readable.push (_stream_readable.js:224:10)
    at internal/fs/streams.js:191:12
    at FSReqCallback.wrapper [as oncomplete] (fs.js:470:5)
0.079 s 6 KBi
#23
Error en tiempo de ejecución (NZEC)
Exited with error status 1
/box/script.js:6
  for (let i = 0; i < adj[index].length; i++) {
                                 ^

TypeError: Cannot read property 'length' of undefined
    at dfs (/box/script.js:6:34)
    at ReadStream.<anonymous> (/box/script.js:24:20)
    at ReadStream.emit (events.js:210:5)
    at addChunk (_stream_readable.js:309:12)
    at readableAddChunk (_stream_readable.js:290:11)
    at ReadStream.Readable.push (_stream_readable.js:224:10)
    at internal/fs/streams.js:191:12
    at FSReqCallback.wrapper [as oncomplete] (fs.js:470:5)
0.019 s 6 KBi
#24
Error en tiempo de ejecución (NZEC)
Exited with error status 1
/box/script.js:6
  for (let i = 0; i < adj[index].length; i++) {
                                 ^

TypeError: Cannot read property 'length' of undefined
    at dfs (/box/script.js:6:34)
    at ReadStream.<anonymous> (/box/script.js:24:20)
    at ReadStream.emit (events.js:210:5)
    at addChunk (_stream_readable.js:309:12)
    at readableAddChunk (_stream_readable.js:290:11)
    at ReadStream.Readable.push (_stream_readable.js:224:10)
    at internal/fs/streams.js:191:12
    at FSReqCallback.wrapper [as oncomplete] (fs.js:470:5)
0.048 s 7 KBi
#25
Error en tiempo de ejecución (NZEC)
Exited with error status 1
/box/script.js:6
  for (let i = 0; i < adj[index].length; i++) {
                                 ^

TypeError: Cannot read property 'length' of undefined
    at dfs (/box/script.js:6:34)
    at ReadStream.<anonymous> (/box/script.js:24:20)
    at ReadStream.emit (events.js:210:5)
    at addChunk (_stream_readable.js:309:12)
    at readableAddChunk (_stream_readable.js:290:11)
    at ReadStream.Readable.push (_stream_readable.js:224:10)
    at internal/fs/streams.js:191:12
    at FSReqCallback.wrapper [as oncomplete] (fs.js:470:5)
0.08 s 6 KBi
#26
Error en tiempo de ejecución (NZEC)
Exited with error status 1
/box/script.js:6
  for (let i = 0; i < adj[index].length; i++) {
                                 ^

TypeError: Cannot read property 'length' of undefined
    at dfs (/box/script.js:6:34)
    at ReadStream.<anonymous> (/box/script.js:24:20)
    at ReadStream.emit (events.js:210:5)
    at addChunk (_stream_readable.js:309:12)
    at readableAddChunk (_stream_readable.js:290:11)
    at ReadStream.Readable.push (_stream_readable.js:224:10)
    at internal/fs/streams.js:191:12
    at FSReqCallback.wrapper [as oncomplete] (fs.js:470:5)
0.023 s 7 KBi
#27
Error en tiempo de ejecución (NZEC)
Exited with error status 1
/box/script.js:17
    const [u,v] = dataArray[i].split(' ').map(n => Number(n));
                               ^

TypeError: Cannot read property 'split' of undefined
    at ReadStream.<anonymous> (/box/script.js:17:32)
    at ReadStream.emit (events.js:210:5)
    at addChunk (_stream_readable.js:309:12)
    at readableAddChunk (_stream_readable.js:290:11)
    at ReadStream.Readable.push (_stream_readable.js:224:10)
    at internal/fs/streams.js:191:12
    at FSReqCallback.wrapper [as oncomplete] (fs.js:470:5)
0.036 s 10 KBi
#28
Error en tiempo de ejecución (NZEC)
Exited with error status 1
/box/script.js:6
  for (let i = 0; i < adj[index].length; i++) {
                                 ^

TypeError: Cannot read property 'length' of undefined
    at dfs (/box/script.js:6:34)
    at ReadStream.<anonymous> (/box/script.js:24:20)
    at ReadStream.emit (events.js:210:5)
    at addChunk (_stream_readable.js:309:12)
    at readableAddChunk (_stream_readable.js:290:11)
    at ReadStream.Readable.push (_stream_readable.js:224:10)
    at internal/fs/streams.js:191:12
    at FSReqCallback.wrapper [as oncomplete] (fs.js:470:5)
0.021 s 7 KBi
#29
Error en tiempo de ejecución (NZEC)
Exited with error status 1
/box/script.js:17
    const [u,v] = dataArray[i].split(' ').map(n => Number(n));
                               ^

TypeError: Cannot read property 'split' of undefined
    at ReadStream.<anonymous> (/box/script.js:17:32)
    at ReadStream.emit (events.js:210:5)
    at addChunk (_stream_readable.js:309:12)
    at readableAddChunk (_stream_readable.js:290:11)
    at ReadStream.Readable.push (_stream_readable.js:224:10)
    at internal/fs/streams.js:191:12
    at FSReqCallback.wrapper [as oncomplete] (fs.js:470:5)
0.035 s 10 KBi
#30
Error en tiempo de ejecución (NZEC)
Exited with error status 1
/box/script.js:6
  for (let i = 0; i < adj[index].length; i++) {
                                 ^

TypeError: Cannot read property 'length' of undefined
    at dfs (/box/script.js:6:34)
    at ReadStream.<anonymous> (/box/script.js:24:20)
    at ReadStream.emit (events.js:210:5)
    at addChunk (_stream_readable.js:309:12)
    at readableAddChunk (_stream_readable.js:290:11)
    at ReadStream.Readable.push (_stream_readable.js:224:10)
    at internal/fs/streams.js:191:12
    at FSReqCallback.wrapper [as oncomplete] (fs.js:470:5)
0.023 s 7 KBi
#31
Error en tiempo de ejecución (NZEC)
Exited with error status 1
/box/script.js:6
  for (let i = 0; i < adj[index].length; i++) {
                                 ^

TypeError: Cannot read property 'length' of undefined
    at dfs (/box/script.js:6:34)
    at ReadStream.<anonymous> (/box/script.js:24:20)
    at ReadStream.emit (events.js:210:5)
    at addChunk (_stream_readable.js:309:12)
    at readableAddChunk (_stream_readable.js:290:11)
    at ReadStream.Readable.push (_stream_readable.js:224:10)
    at internal/fs/streams.js:191:12
    at FSReqCallback.wrapper [as oncomplete] (fs.js:470:5)
0.028 s 9 KBi
#32
Error en tiempo de ejecución (NZEC)
Exited with error status 1
/box/script.js:17
    const [u,v] = dataArray[i].split(' ').map(n => Number(n));
                               ^

TypeError: Cannot read property 'split' of undefined
    at ReadStream.<anonymous> (/box/script.js:17:32)
    at ReadStream.emit (events.js:210:5)
    at addChunk (_stream_readable.js:309:12)
    at readableAddChunk (_stream_readable.js:290:11)
    at ReadStream.Readable.push (_stream_readable.js:224:10)
    at internal/fs/streams.js:191:12
    at FSReqCallback.wrapper [as oncomplete] (fs.js:470:5)
0.103 s 10 KBi
#33
Error en tiempo de ejecución (NZEC)
Exited with error status 1
/box/script.js:17
    const [u,v] = dataArray[i].split(' ').map(n => Number(n));
                               ^

TypeError: Cannot read property 'split' of undefined
    at ReadStream.<anonymous> (/box/script.js:17:32)
    at ReadStream.emit (events.js:210:5)
    at addChunk (_stream_readable.js:309:12)
    at readableAddChunk (_stream_readable.js:290:11)
    at ReadStream.Readable.push (_stream_readable.js:224:10)
    at internal/fs/streams.js:191:12
    at FSReqCallback.wrapper [as oncomplete] (fs.js:470:5)
0.038 s 11 KBi
#34
Error en tiempo de ejecución (NZEC)
Exited with error status 1
/box/script.js:17
    const [u,v] = dataArray[i].split(' ').map(n => Number(n));
                               ^

TypeError: Cannot read property 'split' of undefined
    at ReadStream.<anonymous> (/box/script.js:17:32)
    at ReadStream.emit (events.js:210:5)
    at addChunk (_stream_readable.js:309:12)
    at readableAddChunk (_stream_readable.js:290:11)
    at ReadStream.Readable.push (_stream_readable.js:224:10)
    at internal/fs/streams.js:191:12
    at FSReqCallback.wrapper [as oncomplete] (fs.js:470:5)
0.082 s 11 KBi
#35
Error en tiempo de ejecución (NZEC)
Exited with error status 1
/box/script.js:17
    const [u,v] = dataArray[i].split(' ').map(n => Number(n));
                               ^

TypeError: Cannot read property 'split' of undefined
    at ReadStream.<anonymous> (/box/script.js:17:32)
    at ReadStream.emit (events.js:210:5)
    at addChunk (_stream_readable.js:309:12)
    at readableAddChunk (_stream_readable.js:290:11)
    at ReadStream.Readable.push (_stream_readable.js:224:10)
    at internal/fs/streams.js:191:12
    at FSReqCallback.wrapper [as oncomplete] (fs.js:470:5)
0.07 s 10 KBi
Puntos totales: 12 / 100

Código

const adj = new Map();
let visited;

function dfs(index) {
  visited[index] = true;
  for (let i = 0; i < adj[index].length; i++) {
    if (!visited[i]) {
      return true;
    }
  }
}

process.stdin.on('data', data => {
  const dataArray = data.toString().split('\n');
  const [N, M] = dataArray[0].split(' ').map(n => Number(n));
  for (let i = 1; i <= M; i++) {
    const [u,v] = dataArray[i].split(' ').map(n => Number(n));
    adj[u] = adj[u] || [];
    adj[u].push(v);
  }
  visited = new Array(N).fill(false);
  for (let i = 0; i < N; i++) {
    if (!visited[i]) {
      const resp = dfs(i);
      if (resp) {
        console.log('Yes');
        return;
      }
    }
  }
  console.log('No')
})