Submission #6391711


Source Code Expand

Copy
import heapq

n,m=map(int,input().split())
g=[[] for _ in range(n+1)]
cnt=[0]*(n+1)
for _ in range(m):
  a,b=map(int,input().split())
  g[a].append(b)
  g[b].append(a)
  cnt[a]+=1
  cnt[b]+=1
if m%2==1:
  print(-1)
else:
  q=[]
  for i in range(1,n+1):
    if cnt[i]>=2:
      heapq.heappush(q,(cnt[i],i))
  checked=[0]*(n+1)
  while len(q)!=0:
    val,u=heapq.heappop(q)
    if checked[u]==1:
      continue
    for _ in range((val//2)*2):
      v=g[u][0]
      print(u,v)
      g[u].remove(v)
      g[v].remove(u)
      cnt[u]-=1
      cnt[v]-=1
      if cnt[v]>=2:
        heapq.heappush(q,(cnt[v],v))
      else:
        checked[v]=1
    checked[u]=1

Submission Info

Submission Time
Task B - Even Degrees
User tanon710
Language Python (3.4.3)
Score 0
Code Size 688 Byte
Status WA
Exec Time 1075 ms
Memory 33720 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 700
Status
AC × 2
AC × 14
WA × 22
Set Name Test Cases
Sample s1.txt, s2.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, s1.txt, s2.txt
Case Name Status Exec Time Memory
01.txt WA 870 ms 30444 KB
02.txt WA 886 ms 30220 KB
03.txt WA 842 ms 30208 KB
04.txt WA 838 ms 30220 KB
05.txt AC 412 ms 22084 KB
06.txt WA 887 ms 24948 KB
07.txt WA 896 ms 24928 KB
08.txt WA 892 ms 24952 KB
09.txt WA 926 ms 24852 KB
10.txt AC 393 ms 16580 KB
11.txt WA 811 ms 20956 KB
12.txt WA 794 ms 20948 KB
13.txt WA 794 ms 20968 KB
14.txt WA 790 ms 20972 KB
15.txt AC 357 ms 12276 KB
16.txt WA 864 ms 19308 KB
17.txt WA 860 ms 19268 KB
18.txt WA 879 ms 19184 KB
19.txt WA 881 ms 19228 KB
20.txt AC 355 ms 10860 KB
21.txt WA 1054 ms 17680 KB
22.txt WA 1075 ms 17676 KB
23.txt WA 1051 ms 17668 KB
24.txt WA 1075 ms 17664 KB
25.txt AC 349 ms 8268 KB
26.txt AC 391 ms 21956 KB
27.txt AC 396 ms 21956 KB
28.txt WA 798 ms 33720 KB
29.txt WA 832 ms 33720 KB
30.txt AC 18 ms 3064 KB
31.txt AC 18 ms 3064 KB
32.txt AC 18 ms 3064 KB
33.txt AC 18 ms 3064 KB
34.txt AC 18 ms 3064 KB
s1.txt AC 18 ms 3064 KB
s2.txt AC 18 ms 3064 KB