10822 | 2024-04-15 23:19:45 | 42 | Vasútépítés | python3 | Runtime error 0/100 | 310ms | 93972 KiB |
from sys import stdin,stdout
input=stdin.readline
def main():
N,M = list(map(int, input().split()))
if M>N:
print(-1)
return
graph={}
for i in range(M):
u,v = list(map(int, input().split()))
try: graph[u].add(v)
except: graph[u]={v}
try: graph[v].add(u)
except: graph[v]={u}
if len(graph)<N:
print(-1)
return
deg={}
for key in graph:
try: deg[len(graph[key])].add(key)
except: deg[len(graph[key])]={key}
#print(deg)
#print(graph)
# deg1 -> 1...1000
# deg2 -> 1001...2000
deg1,deg2=2000,1000
inf=10**7
matrix=[list(range(inf-i*1001-N-1,inf-i*1001)) for i in range(0,N+1)]
#print(matrix)
while deg[1]:
v=deg[1].pop()
u=graph.pop(v).pop()
#print(v,u)
matrix[u][v]=deg1
matrix[v][u]=deg1
deg1-=1
if u in deg[1]:
deg[1].remove(u)
graph.pop(u)
else:
graph[u].remove(v)
deg[len(graph[u])].add(u)
if len(deg[len(graph[u])+1])==1:
deg.pop(len(graph[u])+1)
else:
deg[len(graph[u])+1].remove(u)
if len(graph[u])==1:
deg[1].add(u)
if 1 in deg:
deg.pop(1)
if len(deg)>1 or 2 not in deg:
print(-1)
return
#print(deg)
#print(graph)
while deg[2]:
v=deg[2].pop()
cur=[v]
while cur[-1] in graph:
szomsz=graph.pop(cur[-1])
for u in szomsz:
if u in deg[2]:
deg[2].remove(u)
cur.append(u)
break
#print(cur)
for i in range(len(cur)):
u=cur[i]
v=cur[i-1]
matrix[u][v]=deg2
matrix[v][u]=deg2
deg2-=1
#print(N,len(matrix),len(matrix[0]))
for i in range(1,N):
#print(*matrix[i][i+1:])
for j in range(i+1,N+1):
stdout.write(str(matrix[i][j])+' ')
stdout.write('\n')
main()
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 18ms | 11776 KiB | ||||
2 | Accepted | 18ms | 11812 KiB | ||||
3 | Accepted | 21ms | 13272 KiB | ||||
subtask2 | 0/40 | ||||||
4 | Runtime error | 83ms | 92092 KiB | ||||
5 | Wrong answer | 76ms | 92736 KiB | ||||
6 | Wrong answer | 76ms | 92740 KiB | ||||
7 | Wrong answer | 76ms | 92964 KiB | ||||
8 | Runtime error | 83ms | 92960 KiB | ||||
9 | Runtime error | 98ms | 93148 KiB | ||||
10 | Runtime error | 86ms | 93408 KiB | ||||
11 | Wrong answer | 17ms | 13760 KiB | ||||
subtask3 | 0/60 | ||||||
12 | Runtime error | 83ms | 92092 KiB | ||||
13 | Wrong answer | 76ms | 92736 KiB | ||||
14 | Wrong answer | 76ms | 92740 KiB | ||||
15 | Wrong answer | 76ms | 92964 KiB | ||||
16 | Runtime error | 83ms | 92960 KiB | ||||
17 | Runtime error | 98ms | 93148 KiB | ||||
18 | Runtime error | 86ms | 93408 KiB | ||||
19 | Wrong answer | 17ms | 13760 KiB | ||||
20 | Accepted | 296ms | 93372 KiB | ||||
21 | Runtime error | 82ms | 93532 KiB | ||||
22 | Accepted | 310ms | 93548 KiB | ||||
23 | Runtime error | 85ms | 93580 KiB | ||||
24 | Accepted | 296ms | 93724 KiB | ||||
25 | Accepted | 310ms | 93848 KiB | ||||
26 | Accepted | 300ms | 93744 KiB | ||||
27 | Runtime error | 83ms | 93972 KiB | ||||
28 | Accepted | 17ms | 14188 KiB | ||||
29 | Accepted | 19ms | 14888 KiB | ||||
30 | Accepted | 17ms | 14060 KiB | ||||
31 | Accepted | 86ms | 93736 KiB |