# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
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()
Compilation message (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... |