Submission #39261710


Source Code Expand

Copy
from collections import defaultdict, deque
import sys
sys.setrecursionlimit(2 * 10 ** 6)
N, M = map(int, input().split())
edge = defaultdict(list)
larger = set()
for _ in range(M):
X, Y = map(int, input().split())
larger.add(Y)
edge[X].append(Y)
route = []
def dfs(n):
route.append(n)
if len(route) == N:
_, ans = zip(*sorted(zip(route, range(1, N + 1))))
print("Yes")
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
from collections import defaultdict, deque
import sys
 
 
sys.setrecursionlimit(2 * 10 ** 6)

N, M = map(int, input().split())

edge = defaultdict(list)
larger = set()
for _ in range(M):
  X, Y = map(int, input().split())
  larger.add(Y)
  edge[X].append(Y)

route = []
def dfs(n):
  route.append(n)
  if len(route) == N:
    _, ans = zip(*sorted(zip(route, range(1, N + 1))))
    print("Yes")
    print(*ans)
    exit()
  for nxt in edge[n]:
    dfs(nxt)
  route.pop()

first = set(range(1, N + 1)) - larger
if len(first) > 1:
  print("No")
  exit()
  
dfs(first.pop())
print("No")




Submission Info

Submission Time
Task E - Find Permutation
User arakaki_tokyo
Language Python (3.8.2)
Score 0
Code Size 625 Byte
Status TLE
Exec Time 2208 ms
Memory 274620 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 500
Status
AC × 3
AC × 26
TLE × 13
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
hand_01.txt AC 21 ms 9236 KB
hand_02.txt AC 27 ms 9100 KB
hand_03.txt AC 20 ms 9320 KB
hand_04.txt AC 20 ms 9116 KB
random_01.txt AC 316 ms 37332 KB
random_02.txt TLE 2206 ms 10824 KB
random_03.txt AC 407 ms 29572 KB
random_04.txt TLE 2206 ms 9896 KB
random_05.txt AC 1453 ms 274616 KB
random_06.txt AC 620 ms 140740 KB
random_07.txt AC 1471 ms 274616 KB
random_08.txt TLE 2207 ms 52880 KB
random_09.txt AC 1461 ms 274616 KB
random_10.txt TLE 2206 ms 17256 KB
random_11.txt AC 1767 ms 274452 KB
random_12.txt TLE 2208 ms 85548 KB
random_13.txt AC 1454 ms 274464 KB
random_14.txt TLE 2207 ms 53440 KB
random_15.txt AC 1483 ms 274620 KB
random_16.txt TLE 2207 ms 69816 KB
random_17.txt AC 1540 ms 274480 KB
random_18.txt TLE 2206 ms 29576 KB
random_19.txt AC 1516 ms 274492 KB
random_20.txt TLE 2206 ms 17656 KB
random_21.txt TLE 2206 ms 10744 KB
random_22.txt AC 608 ms 80596 KB
random_23.txt AC 80 ms 19072 KB
random_24.txt AC 20 ms 9276 KB
random_25.txt AC 525 ms 35216 KB
random_26.txt AC 360 ms 10696 KB
random_27.txt AC 410 ms 44408 KB
random_28.txt TLE 2206 ms 9840 KB
random_29.txt AC 518 ms 54392 KB
random_30.txt TLE 2206 ms 10320 KB
random_31.txt TLE 2206 ms 9876 KB
random_32.txt AC 31 ms 9128 KB
sample_01.txt AC 20 ms 9096 KB
sample_02.txt AC 21 ms 9304 KB
sample_03.txt AC 22 ms 9204 KB


2025-04-05 (Sat)
08:56:30 +00:00