Submission #6624964


Source Code Expand

Copy
def dfs1(v):
  if len(g[v])==0:
    return 0
  for u in g[v]:
    if checked[u]==0:
      checked[u]=1
      g2[v].append(u)
      dfs1(u)
      g3[v].append(u)
      g3[u].append(v)
      
def dfs2(v):
  if len(g2[v])==0:
    return 0
  for u in g2[v]:
    if checked[u]==0:
      checked[u]=1
      dfs2(u)
      if cnt[u]%2==1:
        ans.append((u,v))
        cnt[u]+=1
      else:
        ans.append((v,u))
        cnt[v]+=1
      
n,m=map(int,input().split())
g=[[] for _ in range(n+1)]
g2=[[] for _ in range(n+1)]
g3=[[] for _ in range(n+1)]
g4=[[] for _ in range(n+1)]
cnt=[0]*(n+1)
ans=[]
for _ in range(m):
  a,b=map(int,input().split())
  g[a].append(b)
  g[b].append(a)
if m%2==1:
  print(-1)
else:
  checked=[0]*(n+1)
  checked[1]=1
  dfs1(1)
  for v in range(1,n+1):
    for u in g[v]:
      if u not in g3[v]:
        g4[v].append(u)
  for v in range(1,n+1):
    for u in g4[v]:
      ans.append((v,u))
      cnt[v]+=1
      g4[v].remove(u)
      g4[u].remove(v)
  checked=[0]*(n+1)
  checked[1]=1
  dfs2(1)
  for v,u in ans:
    print(v,u)

Submission Info

Submission Time
Task B - Even Degrees
User tanon710
Language Python (3.4.3)
Score 0
Code Size 1112 Byte
Status RE
Exec Time 1058 ms
Memory 60636 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 700
Status
AC × 2
AC × 18
WA × 4
RE × 14
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 AC 1014 ms 60532 KB
02.txt AC 995 ms 60576 KB
03.txt AC 1037 ms 60636 KB
04.txt AC 1058 ms 60556 KB
05.txt AC 502 ms 43460 KB
06.txt RE 453 ms 28588 KB
07.txt RE 456 ms 28588 KB
08.txt RE 479 ms 28584 KB
09.txt RE 472 ms 28588 KB
10.txt AC 397 ms 27204 KB
11.txt RE 401 ms 15468 KB
12.txt RE 397 ms 15476 KB
13.txt RE 394 ms 15464 KB
14.txt RE 395 ms 15460 KB
15.txt AC 338 ms 14452 KB
16.txt RE 395 ms 12200 KB
17.txt RE 382 ms 12188 KB
18.txt RE 382 ms 12172 KB
19.txt RE 392 ms 12164 KB
20.txt AC 324 ms 11248 KB
21.txt WA 834 ms 16600 KB
22.txt WA 812 ms 16752 KB
23.txt WA 822 ms 16632 KB
24.txt WA 818 ms 16648 KB
25.txt AC 305 ms 8412 KB
26.txt AC 496 ms 43332 KB
27.txt AC 489 ms 43372 KB
28.txt RE 556 ms 45128 KB
29.txt RE 552 ms 45124 KB
30.txt AC 18 ms 3192 KB
31.txt AC 19 ms 3188 KB
32.txt AC 18 ms 3188 KB
33.txt AC 17 ms 3188 KB
34.txt AC 18 ms 3192 KB
s1.txt AC 19 ms 3316 KB
s2.txt AC 18 ms 3192 KB