# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1171900 | Isam | Naboj (COCI22_naboj) | Pypy 3 | 712 ms | 91920 KiB |
from collections import deque
def main():
n, m = map(int, input().split())
cnt = [0] * (n + 1)
g = [[] for _ in range(n + 1)]
em = []
q = deque()
for _ in range(m):
a, b = map(int, input().split())
g[b].append(a)
cnt[a] += 1
for i in range(1, n + 1):
if cnt[i] == 0:
q.append(i)
while q:
cur = q.popleft()
em.append(cur)
for to in g[cur]:
cnt[to] -= 1
if cnt[to] == 0:
q.append(to)
if len(em) != n:
print(-1)
else:
print(n)
for to in em:
print(to, 1)
if __name__ == "__main__":
main()
컴파일 시 표준 출력 (stdout) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |