Submission #24393748
Source Code Expand
N,M = gets.split.map(&:to_i)
E = Array.new(N){[]}
ヨ = Array.new(N){[]}
M.times{
a,b = gets.split.map{_1.to_i-1}
E[a] << b
ヨ[b] << a
}
v,V = -1,[nil]*N
F = lambda{|a|
V[a] = -1
*q = a
while a = q.pop
0while b = E[a].pop and V[b]
if b
q << a << b
V[b] = -1
else
V[a] = v+=1
end
end
}
N.times{|a|
F[a] if ! V[a]
}
Q = [nil]*N
V.each_with_index{|i,a|
Q[i] = a
}
V.fill nil
v = 0
while a = Q.pop
next if V[a]
V[a] = v+=1
ヨ[a].each{|b|
next if V[b]
V[b] = v
}
end
puts(v==N ? 'No':'Yes')
Submission Info
| Submission Time | |
|---|---|
| Task | J - Never Ending Journey |
| User | ds14050 |
| Language | Ruby (2.7.1) |
| Score | 6 |
| Code Size | 570 Byte |
| Status | AC |
| Exec Time | 463 ms |
| Memory | 49608 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 6 / 6 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | example0.txt, example1.txt |
| All | 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, example0.txt, example1.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 000.txt | AC | 185 ms | 17052 KiB |
| 001.txt | AC | 207 ms | 18572 KiB |
| 002.txt | AC | 209 ms | 18024 KiB |
| 003.txt | AC | 394 ms | 47924 KiB |
| 004.txt | AC | 83 ms | 15924 KiB |
| 005.txt | AC | 82 ms | 15880 KiB |
| 006.txt | AC | 325 ms | 33864 KiB |
| 007.txt | AC | 336 ms | 38748 KiB |
| 008.txt | AC | 446 ms | 49608 KiB |
| 009.txt | AC | 78 ms | 15816 KiB |
| 010.txt | AC | 78 ms | 16008 KiB |
| 011.txt | AC | 448 ms | 49260 KiB |
| 012.txt | AC | 80 ms | 15780 KiB |
| 013.txt | AC | 459 ms | 46796 KiB |
| 014.txt | AC | 445 ms | 46536 KiB |
| 015.txt | AC | 453 ms | 47236 KiB |
| 016.txt | AC | 199 ms | 45460 KiB |
| 017.txt | AC | 199 ms | 45400 KiB |
| 018.txt | AC | 199 ms | 45536 KiB |
| 019.txt | AC | 77 ms | 17404 KiB |
| 020.txt | AC | 77 ms | 17488 KiB |
| 021.txt | AC | 74 ms | 17488 KiB |
| 022.txt | AC | 79 ms | 17536 KiB |
| 023.txt | AC | 75 ms | 17292 KiB |
| 024.txt | AC | 458 ms | 48448 KiB |
| 025.txt | AC | 453 ms | 48700 KiB |
| 026.txt | AC | 453 ms | 48624 KiB |
| 027.txt | AC | 463 ms | 49328 KiB |
| 028.txt | AC | 447 ms | 49400 KiB |
| 029.txt | AC | 78 ms | 14972 KiB |
| 030.txt | AC | 79 ms | 14976 KiB |
| 031.txt | AC | 76 ms | 14588 KiB |
| 032.txt | AC | 77 ms | 14612 KiB |
| 033.txt | AC | 76 ms | 14972 KiB |
| example0.txt | AC | 62 ms | 14340 KiB |
| example1.txt | AC | 57 ms | 14376 KiB |