1 / 3
Mar 2013

I am trying spoj.com/problems/TRANCLS/1.

a=input()
toi=0
while toi<a:
    toi+=1
    start={}    # Dictionary which stores keys as the starting element of the set
    end={}      # Dictionary which stores keys as the ending element of the set
    l=[]
    b=input()
    while b:
        b-=1
        [c,d]=map(int,raw_input("").strip().split())
        l.append([c,d])
        if c not in start.keys():
            start[c]=[[c,d]]
        else:
            start[c].append([c,d])
        if d not in end.keys():
            end[d]=[[c,d]]
        else:
            end[d].append([c,d])
    s=0
#  print start,end,l
    for i in end.keys():    # Starting from end keys and going to starting  one and checking whether the starting of end values and ending of start values set is in l or not 
        if i in start.keys():
            for j in end[i]:
                for k in start[i]:
                    if [j[0],k[1]] not in l:
##                      print [j[0],k[1]]
                        s+=1                               # If it is not Add 1 else do nothing 
    print "Case #%r:"%toi,s

It gives correct answer to the testcases given there and some of my own test cases but it is not being accepted.I think there is some tricky test cases. Someone please help...

  • created

    Mar '13
  • last reply

    Mar '13
  • 2

    replies

  • 277

    views

  • 2

    users

  • 1

    link