Submission #6384422


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:
  path=printCircuit(cand[0])
  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 1291 Byte
Status WA
Exec Time 663 ms
Memory 25120 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 451 ms 24772 KB
02.txt WA 450 ms 24764 KB
03.txt WA 455 ms 24768 KB
04.txt WA 445 ms 24888 KB
05.txt AC 456 ms 24768 KB
06.txt WA 398 ms 17948 KB
07.txt WA 408 ms 17988 KB
08.txt WA 406 ms 17992 KB
09.txt WA 411 ms 17976 KB
10.txt AC 403 ms 17996 KB
11.txt WA 384 ms 12772 KB
12.txt WA 381 ms 12784 KB
13.txt WA 365 ms 12784 KB
14.txt WA 374 ms 12784 KB
15.txt AC 382 ms 12780 KB
16.txt WA 358 ms 11120 KB
17.txt WA 361 ms 11116 KB
18.txt WA 358 ms 11120 KB
19.txt WA 352 ms 11116 KB
20.txt AC 354 ms 11116 KB
21.txt WA 355 ms 8640 KB
22.txt WA 342 ms 8560 KB
23.txt WA 352 ms 8540 KB
24.txt WA 370 ms 8552 KB
25.txt AC 338 ms 8552 KB
26.txt AC 524 ms 24748 KB
27.txt AC 529 ms 24752 KB
28.txt AC 655 ms 25120 KB
29.txt AC 663 ms 25116 KB
30.txt AC 20 ms 3316 KB
31.txt AC 20 ms 3316 KB
32.txt AC 20 ms 3316 KB
33.txt AC 20 ms 3316 KB
34.txt WA 20 ms 3316 KB
s1.txt AC 20 ms 3316 KB
s2.txt AC 20 ms 3316 KB