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

Envío 6011

Problema 0x53 - Encontrar ciclos en un grafo dirigido

  • Autor: jarangolp
  • Fecha: 2022-05-02 13:27:57 UTC (Hace más de 2 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.023 s 6 KBi
#2
Incorrecto
0.063 s 10 KBi
#3
Correcto
0.095 s 6 KBi
#4
Incorrecto
0.026 s 6 KBi
#5
Incorrecto
0.02 s 6 KBi
#6
Incorrecto
0.024 s 6 KBi
#7
Incorrecto
0.071 s 6 KBi
#8
Incorrecto
0.055 s 10 KBi
#9
Incorrecto
0.026 s 6 KBi
#10
Correcto
0.08 s 6 KBi
#11
Correcto
0.049 s 7 KBi
#12
Correcto
0.033 s 7 KBi
#13
Incorrecto
0.018 s 7 KBi
#14
Correcto
0.022 s 6 KBi
#15
Incorrecto
0.026 s 6 KBi
#16
Correcto
0.024 s 6 KBi
#17
Correcto
0.026 s 6 KBi
#18
Correcto
0.025 s 6 KBi
#19
Incorrecto
0.026 s 6 KBi
#20
Incorrecto
0.049 s 7 KBi
#21
Incorrecto
0.078 s 6 KBi
#22
Correcto
0.093 s 6 KBi
#23
Correcto
0.02 s 6 KBi
#24
Correcto
0.019 s 6 KBi
#25
Correcto
0.086 s 6 KBi
#26
Correcto
0.032 s 8 KBi
#27
Error en tiempo de ejecución (NZEC)
Exited with error status 1
/box/script.js:18
    const [u,v] = dataArray[i].split(' ').map(n => Number(n));
                               ^

TypeError: Cannot read property 'split' of undefined
    at ReadStream.<anonymous> (/box/script.js:18: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.064 s 10 KBi
#28
Correcto
0.027 s 8 KBi
#29
Error en tiempo de ejecución (NZEC)
Exited with error status 1
/box/script.js:18
    const [u,v] = dataArray[i].split(' ').map(n => Number(n));
                               ^

TypeError: Cannot read property 'split' of undefined
    at ReadStream.<anonymous> (/box/script.js:18: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.045 s 10 KBi
#30
Correcto
0.031 s 8 KBi
#31
Correcto
0.038 s 10 KBi
#32
Error en tiempo de ejecución (NZEC)
Exited with error status 1
/box/script.js:18
    const [u,v] = dataArray[i].split(' ').map(n => Number(n));
                               ^

TypeError: Cannot read property 'split' of undefined
    at ReadStream.<anonymous> (/box/script.js:18: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.031 s 10 KBi
#33
Error en tiempo de ejecución (NZEC)
Exited with error status 1
/box/script.js:18
    const [u,v] = dataArray[i].split(' ').map(n => Number(n));
                               ^

TypeError: Cannot read property 'split' of undefined
    at ReadStream.<anonymous> (/box/script.js:18: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.074 s 11 KBi
#34
Error en tiempo de ejecución (NZEC)
Exited with error status 1
/box/script.js:18
    const [u,v] = dataArray[i].split(' ').map(n => Number(n));
                               ^

TypeError: Cannot read property 'split' of undefined
    at ReadStream.<anonymous> (/box/script.js:18: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.037 s 11 KBi
#35
Error en tiempo de ejecución (NZEC)
Exited with error status 1
/box/script.js:18
    const [u,v] = dataArray[i].split(' ').map(n => Number(n));
                               ^

TypeError: Cannot read property 'split' of undefined
    at ReadStream.<anonymous> (/box/script.js:18: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.066 s 10 KBi
Puntos totales: 49 / 100

Código

const adj = new Map();
let visited;

function dfs(index) {
  visited[index] = true;
  adj[index] = adj[index] || [];
  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')
})