Submission #6386187


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 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 1350 Byte
Status WA
Exec Time 681 ms
Memory 25248 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 700
Status
AC × 2
AC × 15
WA × 21
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 466 ms 24776 KB
02.txt WA 454 ms 24760 KB
03.txt WA 460 ms 24784 KB
04.txt WA 480 ms 24888 KB
05.txt AC 461 ms 24772 KB
06.txt WA 416 ms 17952 KB
07.txt WA 435 ms 17988 KB
08.txt WA 427 ms 17992 KB
09.txt WA 417 ms 17976 KB
10.txt AC 398 ms 17944 KB
11.txt WA 383 ms 12772 KB
12.txt WA 370 ms 12784 KB
13.txt WA 372 ms 12784 KB
14.txt WA 380 ms 12784 KB
15.txt AC 375 ms 12780 KB
16.txt WA 364 ms 11120 KB
17.txt WA 370 ms 11116 KB
18.txt WA 350 ms 11120 KB
19.txt WA 358 ms 11116 KB
20.txt AC 360 ms 11116 KB
21.txt WA 363 ms 8640 KB
22.txt WA 358 ms 8560 KB
23.txt WA 354 ms 8668 KB
24.txt WA 375 ms 8552 KB
25.txt AC 339 ms 8552 KB
26.txt AC 547 ms 24748 KB
27.txt AC 534 ms 24752 KB
28.txt AC 681 ms 25116 KB
29.txt AC 661 ms 25248 KB
30.txt AC 21 ms 3316 KB
31.txt AC 21 ms 3316 KB
32.txt AC 21 ms 3316 KB
33.txt AC 20 ms 3316 KB
34.txt WA 20 ms 3316 KB
s1.txt AC 21 ms 3316 KB
s2.txt AC 21 ms 3316 KB