I found an interesting problem on https://www.codechef.com/problems/MINIKILL:
Corruption is on the rise in the country of Freedonia, Gru's home. Gru wants to end this for good and for that he needs the help of his beloved minions.
This corruption network can be represented in the form of a tree having N$N$ nodes and N−1$N-1$ edges. The nodes are numbered from 1$1$ to N$N$, and the tree is rooted at node 1$1$. These nodes represent the corrupt officials and each corrupt official works under some other corrupt official except the Boss who is represented by node 1$1$.
Gru believes in divide and conquer and thinks that this network needs to be divided into as many sub-networks as possible.
He commands the minions to kill some of the corrupt officials in order to break the network into maximum sub-networks. But as you know, these corrupt officials are very sharp, and hence these assassinations need to be done very smartly and silently, without leaving any traces.  To achieve this Gru devises a strategy, in which he designs an operation, and that operation can be applied by the minions any number of times (even 0). 
In one operation the minions can select any one leaf node official [that is an official who does not have any other official beneath him] in the graph and kill him along with all his ancestors$ancestors$ officials till the root$root$ of the tree in which the operation is applied (this is done to wipe all traces of the operation). This deleted all those nodes from the graph, and also, while doing so, all the associated edges/connections$edges/connections$ of the leaf node and its ancestors are also destroyed. Hence after applying this operation on any tree, it breaks into some connected components which are also trees, which are the new sub-networks.
Now the minions are a bit lazy and will do the task someday, but they need to submit a report to Gru containing the number of the maximum$maximum$ connected$connected$ components$components$ that they could achieve by applying the operation any number of times. To do this, the minions require your help. So help the minions by finding...

I tried it in Python, but could not do it. Can you solve it?
from sys import stdin,stdout
input=stdin.readline
n=int(input())
a=[[] for i in range(n)]
for i in range(n-1):
    u,v=map(int,input().split())
    a[u-1].append(v-1)
    a[v-1].append(u-1)
b=[0]*n
vis=[0]*n
st=[(0,0)]
vis[0]=1
pa=[0]*n
while st:
    x,y=st.pop()
    b[x]=y
    for i in a[x]:
        if vis[i]==0:
            pa[i]=x
            vis[i]=1
            if x==0:
                st.append((i,y+len(a[x])-1))
            else:
                st.append((i,y+len(a[x])-2))
c=[]
for i in range(1,n):
    if len(a[i])==1:
        c.append((b[i],i))
c.sort()
ans=0
while c:
    x,y=c.pop()
    m=y
    p=0
    while y!=0 and pa[y]!=-1:
        y=pa[y]
        if pa[y]==-1:
            break
        if y!=0:
            p+=(len(a[y])-2)
        else:
            p+=(len(a[y])-1)
    if p>=1:
        p=0
        while m!=0 and pa[m]!=-1:
            x=m
            if pa[m]==-1:
                break
            m=pa[m]
            pa[x]=-1
            if m!=0:
                p+=(len(a[m])-2)
            else:
                p+=(len(a[m])-1)
        if y==0:
            pa[0]=-1
for i in range(n):
    if pa[i]!=-1:
        st=[i]
        pa[i]=-1
        while st:
            x=st.pop()
            for j in a[x]:
                if pa[j]!=-1:
                    pa[j]=-1
                    st.append(j)
        ans+=1
print(ans)