Problem:


Score : 400 points

Problem Statement

Fennec and Snuke are playing a board game.

On the board, there are N cells numbered 1 through N, and N-1 roads, each connecting two cells. Cell a_i is adjacent to Cell b_i through the i-th road. Every cell can be reached from every other cell by repeatedly traveling to an adjacent cell. In terms of graph theory, the graph formed by the cells and the roads is a tree.

Initially, Cell 1 is painted black, and Cell N is painted white. The other cells are not yet colored.
Fennec (who goes first) and Snuke (who goes second) alternately paint an uncolored cell.
More specifically, each player performs the following action in her/his turn:

Fennec: selects an uncolored cell that is adjacent to a black cell, and paints it black.

Snuke: selects an uncolored cell that is adjacent to a white cell, and paints it white.

A player loses when she/he cannot paint a cell. Determine the winner of the game when Fennec and Snuke play optimally.

Constraints

2 \leq N \leq 10^5

1 \leq a_i, b_i \leq N

The given graph is a tree.

Input

Input is given from Standard Input in the following format:

N
a_1 b_1
:
a_{N-1} b_{N-1}

Output

If Fennec wins, print Fennec; if Snuke wins, print Snuke.

Sample Input 1

7
3 6
1 2
3 1
7 4
5 7
1 4

Sample Output 1

Fennec

For example, if Fennec first paints Cell 2 black, she will win regardless of Snuke's moves.

Sample Input 2

4
1 4
4 2
2 3

Sample Output 2

Snuke



Sample input:
7
3 6
1 2
3 1
7 4
5 7
1 4


Sample output:
Fennec

Submission status: Wrong Answer

Solution code:
from collections import deque
n = int(input())
route = [[] for i in range(n)]
for i in range(n-1):
    a , b = map(int,input().split())
    route[a-1].append(b-1)
    route[b-1].append(a-1)

kurokyori = [-1 for i in range(n)]
d = deque()
d.append(0)
kurokyori[0] = 0
kurobasyo = set()
while d:
    now = d.popleft()
    for i in route[now]:
        if i != n-1 and kurokyori[i] == -1:
            kurokyori[i] = kurokyori[now] + 1
            d.append(i)
            kurobasyo.add(i)
        if i == n-1:
            kyori = kurokyori[now] + 1
sirokyori = [-1 for i in range(n)]
sirobasyo = set()
d = deque()
d.append(n-1)
sirokyori[n-1] = 0
while d:
    now = d.popleft()
    for i in route[now]:
        if i != 0 and sirokyori[i] == -1:
            sirokyori[i] = sirokyori[now] + 1
            d.append(i)
            sirobasyo.add(i)

kuro = len(kurobasyo - sirobasyo)
siro = len(sirobasyo - kurobasyo)
kaburi = kurobasyo & sirobasyo
if not kaburi:
    if kuro > siro:
        print("Fennec")
    elif kuro <= siro:
        print("Snuke")
    exit()

if kyori % 2 == 0:
    for i in kaburi:
        if sirokyori[i] == kyori//2 and kurokyori == kyori//2:
            p = i
            break
elif kyori % 2 == 1:
    for i in kaburi:
        if kurokyori[i] == kyori//2 and sirokyori[i] == -(-kyori//2):
            p = i
            break
d = deque()
d.append(0)
visit = [False for i in range(n)]
cou = 0
visit[n-1] = True
while d:
    now = d.popleft()
    for i in route[now]:
        if not visit and i in kaburi:
            visit[i] = True
            if i != p:
                cou += 1
                d.append(i)
kuro += len(kaburi) - cou
siro += cou
if kuro > siro:
    print("Fennec")
elif kuro <= siro:
    print("Snuke")

Submission status: Wrong Answer

Solution code:
from collections import deque
n = int(input())
route = [[] for i in range(n)]
for i in range(n-1):
    a , b = map(int,input().split())
    route[a-1].append(b-1)
    route[b-1].append(a-1)

kurokyori = [-1 for i in range(n)]
d = deque()
d.append(0)
kurokyori[0] = 0
kurobasyo = set()
while d:
    now = d.popleft()
    for i in route[now]:
        if i != n-1 and kurokyori[i] == -1:
            kurokyori[i] = kurokyori[now] + 1
            d.append(i)
            kurobasyo.add(i)
        if i == n-1:
            kyori = kurokyori[now] + 1
sirokyori = [-1 for i in range(n)]
sirobasyo = set()
d = deque()
d.append(n-1)
sirokyori[n-1] = 0
while d:
    now = d.popleft()
    for i in route[now]:
        if i != 0 and sirokyori[i] == -1:
            sirokyori[i] = sirokyori[now] + 1
            d.append(i)
            sirobasyo.add(i)

kuro = len(kurobasyo - sirobasyo)
siro = len(sirobasyo - kurobasyo)
kaburi = kurobasyo & sirobasyo
if not kaburi:
    if kuro > siro:
        print("Fennec")
    elif kuro <= siro:
        print("Snuke")
    exit()

if kyori % 2 == 0:
    for i in kaburi:
        if sirokyori[i] == kyori//2 and kurokyori == kyori//2:
            p = i
            break
elif kyori % 2 == 1:
    for i in kaburi:
        if kurokyori[i] == kyori//2 and sirokyori[i] == -(-kyori//2):
            p = i
            break
d = deque()
d.append(0)
visit = [False for i in range(n)]
cou = 0
visit[n-1] = True
while d:
    now = d.popleft()
    for i in route[now]:
        if not visit and i in kaburi:
            cou += 1
            visit[i] = True
            if i != p:
                d.append(i)
kuro += len(kaburi) - cou
siro += cou
if kuro > siro:
    print("Fennec")
elif kuro <= siro:
    print("Snuke")

Submission status: Wrong Answer

Solution code:
from collections import deque
n = int(input())
route = [[] for i in range(n)]
for i in range(n-1):
    a , b = map(int,input().split())
    route[a-1].append(b-1)
    route[b-1].append(a-1)

kurokyori = [-1 for i in range(n)]
d = deque()
d.append(0)
kurokyori[0] = 0
kurobasyo = set()
while d:
    now = d.popleft()
    for i in route[now]:
        if i != n-1 and kurokyori[i] == -1:
            kurokyori[i] = kurokyori[now] + 1
            d.append(i)
            kurobasyo.add(i)
        if i == n-1:
            kyori = kurokyori[now] + 1
sirokyori = [-1 for i in range(n)]
sirobasyo = set()
d = deque()
d.append(n-1)
sirokyori[n-1] = 0
while d:
    now = d.popleft()
    for i in route[now]:
        if i != 0 and sirokyori[i] == -1:
            sirokyori[i] = sirokyori[now] + 1
            d.append(i)
            sirobasyo.add(i)

kuro = len(kurobasyo - sirobasyo)
siro = len(sirobasyo - kurobasyo)
kaburi = kurobasyo & sirobasyo
if not kaburi:
    if kuro > siro:
        print("Fennec")
    elif kuro <= siro:
        print("Snuke")
    exit()

if kyori % 2 == 0:
    for i in kaburi:
        if sirokyori[i] == kyori//2 and kurokyori == kyori//2:
            p = i
            break
elif kyori % 2 == 1:
    for i in kaburi:
        if kurokyori[i] == kyori//2 and sirokyori[i] == -(-kyori//2):
            p = i
            break
d = deque()
d.append(0)
visit = [False for i in range(n)]
cou = 0
visit[0] = True
while d:
    now = d.popleft()
    for i in route[now]:
        if not visit and i in kaburi:
            cou += 1
            visit[i] = True
            if i != p:
                d.append(i)
kuro += cou
siro += len(kaburi) - cou
if kuro > siro:
    print("Fennec")
elif kuro <= siro:
    print("Snuke")

Submission status: Wrong Answer

Solution code:
from collections import deque
n = int(input())
route = [[] for i in range(n)]
for i in range(n-1):
    a , b = map(int,input().split())
    route[a-1].append(b-1)
    route[b-1].append(a-1)
kurokyori = [-1 for i in range(n)]
d = deque()
d.append(0)
kurokyori[0] = 0
kurobasyo = set()
while d:
    now = d.popleft()
    for i in route[now]:
        if i != n-1 and kurokyori[i] == -1:
            kurokyori[i] = kurokyori[now] + 1
            d.append(i)
            kurobasyo.add(i)
        if i == n-1:
            kyori = kurokyori[now] + 1
sirokyori = [-1 for i in range(n)]
sirobasyo = set()
d = deque()
d.append(n-1)
sirokyori[n-1] = 0
while d:
    now = d.popleft()
    for i in route[now]:
        if i != 0 and sirokyori[i] == -1:
            sirokyori[i] = sirokyori[now] + 1
            d.append(i)
            sirobasyo.add(i)

kuro = len(kurobasyo.difference(sirobasyo))
siro = len(sirobasyo.difference(kurobasyo))
kaburi = kurobasyo & sirobasyo
if not kaburi:
    if kuro > siro:
        print("Fennec")
    elif kuro <= siro:
        print("Snuke")
    exit()

if kyori % 2 == 0:
    for i in kaburi:
        if sirokyori[i] == kurokyori[i]:
            p = i
            break
elif kyori % 2 == 1:
    for i in kaburi:
        if kurokyori[i] == kyori//2 and sirokyori[i] == -(-kyori//2):
            p = i
            break
d = deque()
d.append(0)
visit = [False for i in range(n)]
cou = 0
visit[0] = True
while d:
    now = d.popleft()
    for i in route[now]:
        if not visit and i in kaburi:
            cou += 1
            visit[i] = True
            if i != p:
                d.append(i)
kuro += cou
siro += len(kaburi) - cou
if kuro > siro:
    print("Fennec")
elif kuro <= siro:
    print("Snuke")

Submission status: Wrong Answer

Solution code:
from collections import deque
n = int(input())
route = [[] for i in range(n)]
for i in range(n-1):
    a , b = map(int,input().split())
    route[a-1].append(b-1)
    route[b-1].append(a-1)
kurokyori = [-1 for i in range(n)]
d = deque()
d.append(0)
kurokyori[0] = 0
kurobasyo = set()
while d:
    now = d.popleft()
    for i in route[now]:
        if i != n-1 and kurokyori[i] == -1:
            kurokyori[i] = kurokyori[now] + 1
            d.append(i)
            kurobasyo.add(i)
        if i == n-1:
            kyori = kurokyori[now] + 1
sirokyori = [-1 for i in range(n)]
sirobasyo = set()
d = deque()
d.append(n-1)
sirokyori[n-1] = 0
while d:
    now = d.popleft()
    for i in route[now]:
        if i != 0 and sirokyori[i] == -1:
            sirokyori[i] = sirokyori[now] + 1
            d.append(i)
            sirobasyo.add(i)

kuro = len(kurobasyo.difference(sirobasyo))
siro = len(sirobasyo.difference(kurobasyo))
kaburi = kurobasyo & sirobasyo
if not kaburi:
    if kuro > siro:
        print("Fennec")
    elif kuro <= siro:
        print("Snuke")
    exit()

if kyori % 2 == 0:
    for i in kaburi:
        if sirokyori[i] == kurokyori[i]:
            p = i
            break
elif kyori % 2 == 1:
    for i in kaburi:
        if kurokyori[i] == kyori//2 and sirokyori[i] == -(-kyori//2):
            p = i
            break
d = deque()
d.append(0)
visit = [False for i in range(n)]
cou = 0
while d:
    now = d.popleft()
    for i in route[now]:
        if not visit and i in kaburi:
            cou += 1
            visit[i] = True
            if i != p:
                d.append(i)
kuro += cou
siro += len(kaburi) - cou
if kuro > siro:
    print("Fennec")
elif kuro <= siro:
    print("Snuke")

Submission status: Wrong Answer

Solution code:
from collections import deque
n = int(input())
route = [[] for i in range(n)]
for i in range(n-1):
    a , b = map(int,input().split())
    route[a-1].append(b-1)
    route[b-1].append(a-1)
kurokyori = [-1 for i in range(n)]
d = deque()
d.append(0)
kurokyori[0] = 0
kurobasyo = set()
while d:
    now = d.popleft()
    for i in route[now]:
        if i != n-1 and kurokyori[i] == -1:
            kurokyori[i] = kurokyori[now] + 1
            d.append(i)
            kurobasyo.add(i)
        if i == n-1:
            kyori = kurokyori[now] + 1
sirokyori = [-1 for i in range(n)]
sirobasyo = set()
d = deque()
d.append(n-1)
sirokyori[n-1] = 0
while d:
    now = d.popleft()
    for i in route[now]:
        if i != 0 and sirokyori[i] == -1:
            sirokyori[i] = sirokyori[now] + 1
            d.append(i)
            sirobasyo.add(i)

kuro = len(kurobasyo.difference(sirobasyo))
siro = len(sirobasyo.difference(kurobasyo))
kaburi = kurobasyo & sirobasyo
if not kaburi:
    if kuro > siro:
        print("Fennec")
    elif kuro <= siro:
        print("Snuke")
    exit()

if kyori % 2 == 0:
    for i in kaburi:
        if sirokyori[i] == kurokyori[i]:
            p = i
            break
elif kyori % 2 == 1:
    for i in kaburi:
        if kurokyori[i] == kyori//2 and sirokyori[i] == -(-kyori//2):
            p = i
            break
d = deque()
d.append(0)
visit = [False for i in range(n)]
cou = 0
while d:
    now = d.popleft()
    for i in route[now]:
        if not visit:
            cou += 1
            visit[i] = True
            if i != p:
                d.append(i)
kuro += cou
siro += len(kaburi) - cou
if kuro > siro:
    print("Fennec")
elif kuro <= siro:
    print("Snuke")

Submission status: Wrong Answer

Solution code:
from collections import deque
n = int(input())
abss = []
g = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    abss.append((a-1,b-1))
    g[a-1].append(b-1)
    g[b-1].append(a-1)

ds = [-1]*n
dq = deque([(0,"0")])
ds = [-1]*n
n_l_total = []
s_final = [0]
while dq:
    end = True
    idx, s = dq.popleft()
    for i in g[idx]:
        if ds[i] == -1:
            end = False
            ds[i] = 1
            s_tmp = s + ":" + str(i)
            if i == n-1 and s_final[0] == 0:
                s_final[0] = s_tmp
            else:
                dq.append((i,s_tmp))
    if end:
        if s.find(str(n-1)) == -1:
            tmp = s.split(':')
            for j in tmp:
                if j not in n_l_total:
                    n_l_total.append(j)

root = s_final[0].split(':')
len_root = len(root)
n_r = len_root // 2
n_l = len_root - n_r
#print(root)
#print(n_r)
#print(n_l)
n_l_total_len = len(set(n_l_total+root[:n_l]))
#print(n_l_total)
#print(n_l_total_len)
if n_l_total_len > n // 2:
    print("Fennec")
else:
    print("Snuke")

Submission status: Wrong Answer

Solution code:
n = int(input())
abss = []
g = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    abss.append((a-1,b-1))
    g[a-1].append(b-1)
    g[b-1].append(a-1)

ds = [-1]*n
n_l_total = [0]
def dfs(idx,s):
    ds[idx] = 1
    ret = None
    for i in g[idx]:
        if ds[i] == -1:
            s_tmp = s + ":" + str(i)
            if i == n-1:
                return s_tmp
            else:
                ret = dfs(i,s_tmp)
                if ret != None:
                    return ret
    else:
        if s.find(str(n-1)) == -1:
            n_l_total[0] += 1
    return ret
try:
    root = dfs(0,"0").split(':')
except:
    root = list(range(n))
len_root = len(root)
n_r = len_root // 2
n_l = len_root - n_r
if n_l_total[0]+n_l > n // 2:
    print("Fennec")
else:
    print("Snuke")

Submission status: Wrong Answer

Solution code:
import sys 
from collections import defaultdict
finput=lambda:sys.stdin.readline().strip()

class Unionfind():
    def __init__(self,n):
        self.n=n
        self.parents=[-1]*n
        self.ranks=[0]*n
    
    def find(self,x):
        if self.parents[x]<0:
            return x
        else:
            self.parents[x]=self.find(self.parents[x])
            return self.parents[x]
    
    def union(self,x,y):
        x=self.find(x)
        y=self.find(y)
        if x==y:
            return 
        if self.ranks[x]<self.ranks[y]:
            x,y=y,x
        self.parents[x]+=self.parents[y]
        self.parents[y]=x
        if self.ranks[x]==self.ranks[y]:
            self.ranks[x]+=1
    
    def size(self,x):
        return -self.parents[self.find(x)]
    
    def issametree(self,x,y):
        return self.find(x)==self.find(y)

    def showroots(self):
        return [x for x in range(self.n) if self.parents[x]<0]

def main():
    def findgp(d,v):
        fg=defaultdict(int)
        s=[0,0,0]
        s[0]=sum([v.size(x) for x in d[1]])
        s[1]=sum([v.size(x) for x in d[n]])
        for x in d[1]:
            fg[x]=v.find(x)
        for x in d[n]:
            if fg[x]>0:
                s[2]=v.size(x)
                s[0]=s[0]-s[2]
                s[1]=s[1]-s[2]
                return s
        s[0]-=1
        s[1]-=1
        return s
    n=int(finput())
    edges=[tuple(map(int,finput().split())) for _ in range(n-1)]
    d=defaultdict(list)
    v=Unionfind(n+1)
    for e in edges:
        if (e[0]-1)*(e[0]-n)*(e[1]-1)*(e[1]-n)>0:
            v.union(e[0],e[1])
        else:
            d[e[0]].append(e[1])
            d[e[1]].append(e[0])
    s=findgp(d,v)
    #print(d,s)
    if s[0]>s[1] or s[1]-s[0]==1-s[2]%2:
        print('Fennec')
    else:
        print('Snuke')

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys 
from collections import defaultdict
finput=lambda:sys.stdin.readline().strip()

class Unionfind():
    def __init__(self,n):
        self.n=n
        self.parents=[-1]*n
        self.ranks=[0]*n
    
    def find(self,x):
        if self.parents[x]<0:
            return x
        else:
            self.parents[x]=self.find(self.parents[x])
            return self.parents[x]
    
    def union(self,x,y):
        x=self.find(x)
        y=self.find(y)
        if x==y:
            return 
        if self.ranks[x]<self.ranks[y]:
            x,y=y,x
        self.parents[x]+=self.parents[y]
        self.parents[y]=x
        if self.ranks[x]==self.ranks[y]:
            self.ranks[x]+=1
    
    def size(self,x):
        return -self.parents[self.find(x)]
    
    def issametree(self,x,y):
        return self.find(x)==self.find(y)

    def showroots(self):
        return [x for x in range(self.n) if self.parents[x]<0]

def main():
    def findgp(d,v):
        fg=defaultdict(int)
        s=[0,0,0]
        s[0]=sum([v.size(x) for x in d[1]])
        s[1]=sum([v.size(x) for x in d[n]])
        for x in d[1]:
            fg[x]=v.find(x)
        for x in d[n]:
            if fg[x]>0:
                s[2]=v.size(x)
                s[0]=s[0]-s[2]
                s[1]=s[1]-s[2]
                return s
        s[0]-=1
        s[1]-=1
        return s
    n=int(finput())
    edges=[tuple(map(int,finput().split())) for _ in range(n-1)]
    d=defaultdict(list)
    v=Unionfind(n+1)
    for e in edges:
        if (e[0]-1)*(e[0]-n)*(e[1]-1)*(e[1]-n)>0:
            v.union(e[0],e[1])
        else:
            d[e[0]].append(e[1])
            d[e[1]].append(e[0])
    s=findgp(d,v)
    print(d,s)
    if s[0]>s[1] or s[1]-s[0]==1-s[2]%2:
        print('Fennec')
    else:
        print('Snuke')

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys 
from collections import defaultdict
finput=lambda:sys.stdin.readline().strip()

class Unionfind():
    def __init__(self,n):
        self.parents=[-1]*n
        self.ranks=[0]*n
    
    def find(self,x):
        if self.parents[x]<0:
            return x
        else:
            self.parents[x]=self.find(self.parents[x])
            return self.parents[x]
    
    def union(self,x,y):
        x=self.find(x)
        y=self.find(y)
        if x==y:
            return 
        if self.ranks[x]<self.ranks[y]:
            x,y=y,x
        self.parents[x]+=self.parents[y]
        self.parents[y]=x
        if self.ranks[x]==self.ranks[y]:
            self.ranks[x]+=1
    
    def size(self,x):
        return -self.parents[self.find(x)]
    
    def issametree(self,x,y):
        return self.find(x)==self.find(y)

    def showroots(self):
        return [x for x in range(n) if self.parents[x]<0]

def main():
    def findgp(d,v):
        fb=defaultdict(int)
        s=[0,0,0]
        s[0]=sum([v.size(x) for x in d[1]])+len(d[1])-1
        s[1]=sum([v.size(x) for x in d[n]])+len(d[n])-1
        for x in d[1]:
            fb[x]=v.find(x)
        for x in d[n]:
            if fb[x]>0:
                s[2]=v.size(x)+2
                s[0]=s[0]-s[2]+1
                s[1]=s[1]-s[2]+1
                break
        return s
    n=int(finput())
    edges=[tuple(map(int,finput().split())) for _ in range(n-1)]
    d=defaultdict(list)
    v=Unionfind(n+1)
    for e in edges:
        if (e[0]-1)*(e[0]-n)*(e[1]-1)*(e[1]-n)>0:
            v.union(e[0],e[1])
        else:
            d[e[0]].append(e[1])
            d[e[1]].append(e[0])
    s=findgp(d,v)
    if s[0]>s[1] or s[1]-s[0]==1-s[2]%2:
        print('Fennec')
    else:
        print('Snuke')

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *AB = map(int, read().split())
    G = [[] for _ in range(N)]
    for a, b in zip(*[iter(AB)] * 2):
        G[a - 1].append(b - 1)
        G[b - 1].append(a - 1)

    dist1 = [-1] * N
    dist1[0] = 0
    queue = deque([0])
    while queue:
        v = queue.popleft()
        for nv in G[v]:
            if dist1[nv] == -1:
                dist1[nv] = dist1[v] + 1
                if nv != N - 1:
                    queue.append(nv)

    dist2 = [-1] * N
    dist2[N - 1] = 0
    queue = deque([0])
    while queue:
        v = queue.popleft()
        for nv in G[v]:
            if dist2[nv] == -1:
                dist2[nv] = dist2[v] + 1
                if nv != 0:
                    queue.append(nv)

    F = S = 0
    for i, (d1, d2) in enumerate(zip(dist1, dist2)):
        if i in (0, N - 1):
            continue
        if d1 == -1:
            S += 1
        elif d2 == -1:
            F += 1
        elif d1 <= d2:
            S += 1
        else:
            F += 1

    if F > S:
        print('Fennec')
    else:
        print('Snuke')

    return


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *AB = map(int, read().split())
    G = [[] for _ in range(N)]
    for a, b in zip(*[iter(AB)] * 2):
        G[a - 1].append(b - 1)
        G[b - 1].append(a - 1)

    dist = [-1] * N
    dist[0] = 0
    seen = 0
    queue = deque([0])

    while queue:
        v = queue.popleft()
        for nv in G[v]:
            if dist[nv] == -1:
                dist[nv] = dist[v] + 1
                seen += 1
                if nv != N - 1:
                    queue.append(nv)

    F = seen - dist[N - 1] + (dist[N - 1]) // 2
    S = N - F - 2

    if F > S:
        print('Fennec')
    else:
        print('Snuke')

    return


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *AB = map(int, read().split())
    G = [[] for _ in range(N)]
    for a, b in zip(*[iter(AB)] * 2):
        G[a - 1].append(b - 1)
        G[b - 1].append(a - 1)

    dist = [-1] * N
    dist[0] = 0
    seen = 1
    queue = deque([0])

    while queue:
        v = queue.popleft()
        for nv in G[v]:
            if dist[nv] == -1:
                dist[nv] = dist[nv] + 1
                seen += 1
                if nv != N - 1:
                    queue.append(nv)

    F = seen - dist[N - 1] + (dist[N - 1] + 1) // 2
    S = N - F

    if F > S:
        print('Fennec')
    else:
        print('Snuke')

    return


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(1000000000)
input = sys.stdin.readline
n = int(input())
es=[[] for i in range(n)]
for i in range(n - 1):
   a, b = map(int, input().split())
   es[a - 1].append(b - 1)
   es[b - 1].append(a - 1)
def dfs0(v, d, p):
    if v == n - 1:
        return d
    if es[v]:
        ans = 0
        for e in es[v]:
            if e != p:
                ans += dfs0(e, d + 1, v)
        return ans
    return 0

def dfs1(v, p):
    if v == n - 1:
        return 0
    cnt = 1
    for e in es[v]:
        if e != p:
            cnt += dfs1(e, v)
    return cnt

def dfs2(v, p):
    if v == 0:
        return 0
    cnt = 1
    for e in es[v]:
        if e != p:
            cnt += dfs2(e, v)
    return cnt

if dfs0(0, -1, -1) % 2 + dfs1(0, -1) >= dfs2(n - 1, -1):
    print("Fennec")
else:
    print("Snuke")

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(1000000000)
input = sys.stdin.readline
n = int(input())
es=[[] for i in range(n)]
for i in range(n - 1):
   a, b = map(int, input().split())
   es[a - 1].append(b - 1)
   es[b - 1].append(a - 1)
def dfs0(v, d, p):
    if v == n - 1:
        return d
    if es[v]:
        ans = 0
        for e in es[v]:
            if e != p:
                ans += dfs0(e, d + 1, v)
        return ans
    return 0

def dfs1(v, p):
    if v == n - 1:
        return 0
    cnt = 1
    for e in es[v]:
        if e != p:
            cnt += dfs1(e, v)
    return cnt

def dfs2(v, p):
    if v == 0:
        return 0
    cnt = 1
    for e in es[v]:
        if e != p:
            cnt += dfs2(e, v)
    return cnt

if dfs0(0, -1, -1) % 2 + dfs1(0, -1) > dfs2(n - 1, -1):
    print("Fennec")
else:
    print("Snuke")

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(1000000000)
input = sys.stdin.readline
n = int(input())
es=[[] for i in range(n)]
for i in range(n - 1):
   a, b = map(int, input().split())
   es[a - 1].append(b - 1)
   es[b - 1].append(a - 1)
def dfs0(v, d, p):
    if v == n - 1:
        return d
    if es[v]:
        ans = 0
        for e in es[v]:
            if e != p:
                ans += dfs0(e, d + 1, v)
        return ans
    return 0

def dfs1(v, p):
    if v == n - 1:
        return 0
    cnt = 1
    for e in es[v]:
        if e != p:
            cnt += dfs1(e, v)
    return cnt

def dfs2(v, p):
    if v == 0:
        return 0
    cnt = 1
    for e in es[v]:
        if e != p:
            cnt += dfs2(e, v)
    return cnt

if dfs0(0, 0, -1) % 2 + dfs1(0, -1) > dfs2(n - 1, -1):
    print("Fennec")
else:
    print("Snuke")

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
query = [[] for _ in range(N)]
ab = []
for _ in range(N-1):
    a, b = mapint()
    query[a-1].append(b-1)
    query[b-1].append(a-1)
    ab.append((a-1, b-1))

checked = [0]*N
break_point = []
def dfs(now, cnt, lis):
    lis = lis[:]
    if now==N-1:
        leng = len(lis)
        break_point.append(lis[-int(-leng/2)])
        break_point.append(lis[-int(-leng/2)-1])
        return
    checked[now] = 1
    for nx in query[now]:
        if not checked[nx]:
            lis.append(nx)
            dfs(nx, cnt+1, lis)
            lis.pop()
dfs(0, 0, [0])
cnt = 0
checked = [0]*N
def dfs2(now):
    global cnt
    checked[now] = 1
    cnt += 1
    for nx in query[now]:
        if now in break_point and nx in break_point: continue
        if not checked[nx]:
            dfs2(nx)
dfs2(0)
if cnt>N//2:
    print('Fennec')
else:
    print('Snuke')

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
query = [[] for _ in range(N)]
ab = []
for _ in range(N-1):
    a, b = mapint()
    query[a-1].append(b-1)
    query[b-1].append(a-1)
    ab.append((a-1, b-1))

checked = [0]*N
break_point = []
def dfs(now, cnt, lis):
    if now==N-1:
        leng = len(lis)
        break_point.append(lis[-int(-leng/2)])
        break_point.append(lis[-int(-leng/2)-1])
        return
    checked[now] = 1
    for nx in query[now]:
        if not checked[nx]:
            lis.append(nx)
            dfs(nx, cnt+1, lis)
            lis.pop()
dfs(0, 0, [0])
cnt = 0
checked = [0]*N
def dfs2(now):
    global cnt
    checked[now] = 1
    cnt += 1
    for nx in query[now]:
        if now in break_point and nx in break_point: continue
        if not checked[nx]:
            dfs2(nx)
dfs2(0)
if sum(checked)>N//2:
    print('Fennec')
else:
    print('Snuke')

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
query = [[] for _ in range(N)]
ab = []
for _ in range(N-1):
    a, b = mapint()
    query[a-1].append(b-1)
    query[b-1].append(a-1)
    ab.append((a-1, b-1))

checked = [0]*N
break_point = []
def dfs(now, cnt, lis):
    if now==N-1:
        leng = len(lis)
        break_point.append(lis[-int(-leng/2)])
        break_point.append(lis[-int(-leng/2)-1])
        return
    checked[now] = 1
    for nx in query[now]:
        if not checked[nx]:
            lis.append(nx)
            dfs(nx, cnt+1, lis)
            lis.pop()
dfs(0, 0, [0])
cnt = 0
checked = [0]*N
def dfs2(now):
    global cnt
    checked[now] = 1
    cnt += 1
    for nx in query[now]:
        if now in break_point and nx in break_point: continue
        if not checked[nx]:
            dfs2(nx)
dfs2(0)
if cnt>=N//2:
    print('Fennec')
else:
    print('Snuke')

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
query = [[] for _ in range(N)]
ab = []
for _ in range(N-1):
    a, b = mapint()
    query[a-1].append(b-1)
    query[b-1].append(a-1)
    ab.append((a-1, b-1))

checked = [0]*N
break_point = []
def dfs(now, cnt, lis):
    if now==N-1:
        leng = len(lis)
        break_point.append(lis[-int(-leng/2)])
        break_point.append(lis[-int(-leng/2)-1])
        return
    checked[now] = 1
    for nx in query[now]:
        if not checked[nx]:
            lis.append(nx)
            dfs(nx, cnt+1, lis)
            lis.pop()
dfs(0, 0, [0])
cnt = 0
checked = [0]*N
def dfs2(now):
    global cnt
    checked[now] = 1
    cnt += 1
    for nx in query[now]:
        if now in break_point and nx in break_point: continue
        if not checked[nx]:
            dfs2(nx)
dfs2(0)
if cnt>N//2:
    print('Fennec')
else:
    print('Snuke')

Submission status: Wrong Answer

Solution code:
import itertools
from collections import deque

def distance(edge,v):
    n = len(edge)
    visited = [-1]*n
    dist = [0]*n
    que = deque()
    for i in edge[v]:
        que.append([i,1])
        dist[i]=1
        visited[i]=1
    visited[n-1]=1
    visited[0]=1
    while que:
        vertex_=que.popleft()
        d = vertex_[1]
        vertex = vertex_[0]
        visited[vertex]=1

        for next_v in edge[vertex]:
            if visited[next_v]!=-1:continue
            if(next_v==n-1 or next_v==0):
                continue
            dist[next_v]=dist[vertex]+1
            que.append([next_v,dist[next_v]])
    return dist

def main():
    n=int(input())
    edge = [[] for _ in range(n)]
    for i in range(n-1):
        a,b=map(int, input().split())
        edge[a-1].append(b-1)
        edge[b-1].append(a-1)
    mx_d=0
    fenec = distance(edge,0)
    snuke = distance(edge,n-1)
    dis = snuke[0]
    f=0
    s=0
    for i in range(n-1):
        if(fenec[i]>0 and snuke[i]>0):
            continue
        else:
            if(fenec[i]>0):
                f+=1
            if(snuke[i]>0):
                s+=1
    if(dis%2==0):
        if(f>=s):
            print("Fennec")
        else:
            print("Snuke")
    else:
        if(s>=f):
            print("Snuke")
        else:
            print("Fennec")


if __name__ == '__main__':
    main()