Submission #6386296


Source Code Expand

Copy
import collections

def printCircuit(v):
  edge_count=[0]*(n+1)
  for i in range(1,n+1):
    edge_count[i]=len(g[i])
  curr_path=collections.deque()
  circuit=[]
  curr_path.appendleft(v)
  curr_v=v
  while len(curr_path)!=0:
    if edge_count[curr_v]:
      curr_path.appendleft(curr_v)
      next_v=g[curr_v].pop(-1)
      g[next_v].remove(curr_v)
      edge_count[curr_v]-=1
      edge_count[next_v]-=1
      curr_v=next_v
    else:
      circuit.append(curr_v)
      curr_v=curr_path.popleft()
  return circuit

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
cnt1=0
cnt2=0
cand=[]
for i in range(1,n+1):
  if cnt[i]%2==0:
    cnt1+=1
  else:
    cnt2+=1
    cand.append(i)
if m%2==1:
  print(-1)
  else:
  if cnt1==n:
    path=printCircuit(1)
    if len(path)%2==1:
      for i in range(len(path)):
        if i%2==1:
          print(path[i],path[i-1])
          print(path[i],path[i+1])
    else:
      print(-1)
  elif cnt1==n-2 and cnt2==2:
    if len(g[cand[0]])==1:
      c=cand[0]
    else:
      c=cand[1]
    path=printCircuit(c)
    if len(path)%2==1:
      for i in range(len(path)):
        if i%2==1:
          print(path[i],path[i-1])
          print(path[i],path[i+1])
    else:
      print(-1)
  else:
    print(-1)

Submission Info

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

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 700
Status
RE × 2
RE × 36
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 RE 17 ms 3064 KB
02.txt RE 17 ms 3064 KB
03.txt RE 17 ms 3064 KB
04.txt RE 17 ms 3064 KB
05.txt RE 17 ms 3064 KB
06.txt RE 17 ms 3064 KB
07.txt RE 17 ms 3064 KB
08.txt RE 17 ms 3064 KB
09.txt RE 17 ms 3064 KB
10.txt RE 17 ms 3064 KB
11.txt RE 17 ms 3064 KB
12.txt RE 17 ms 3064 KB
13.txt RE 17 ms 3064 KB
14.txt RE 17 ms 3064 KB
15.txt RE 17 ms 3064 KB
16.txt RE 17 ms 3064 KB
17.txt RE 17 ms 3064 KB
18.txt RE 17 ms 3064 KB
19.txt RE 17 ms 3064 KB
20.txt RE 17 ms 3064 KB
21.txt RE 17 ms 3064 KB
22.txt RE 17 ms 3064 KB
23.txt RE 17 ms 3064 KB
24.txt RE 17 ms 3064 KB
25.txt RE 17 ms 3064 KB
26.txt RE 17 ms 3064 KB
27.txt RE 17 ms 3064 KB
28.txt RE 17 ms 3064 KB
29.txt RE 17 ms 3064 KB
30.txt RE 17 ms 3064 KB
31.txt RE 17 ms 3064 KB
32.txt RE 17 ms 3064 KB
33.txt RE 17 ms 3064 KB
34.txt RE 17 ms 3064 KB
s1.txt RE 17 ms 3064 KB
s2.txt RE 17 ms 3064 KB