output_description: Print the answer.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
      a_1 b_1
      \vdots
      a_{N-1} b_{N-1}
attempt: import sys
  
  input = sys.stdin.readline
  mod = 998244353
  
  N = int(input())
  E = [[] for i in range(N + 1)]
  
  for i in range(N - 1):
      x, y = map(int, input().split())
      E[x].append(y)
      E[y].append(x)
  
  Q = [1]
  D = [-1] * (N + 1)
  D[1] = 0
  while Q:
      x = Q.pop()
      for to in E[x]:
          if D[to] == -1:
              D[to] = D[x] + 1
              Q.append(to)
  
  f = D.index(max(D))
  Q = [f]
  D = [-1] * (N + 1)
  D[f] = 0
  while Q:
      x = Q.pop()
      for to in E[x]:
          if D[to] == -1:
              D[to] = D[x] + 1
              Q.append(to)
  
  MAX = max(D)
  l = D.index(MAX)
  Q = [l]
  D2 = [-1] * (N + 1)
  D2[l] = 0
  while Q:
      x = Q.pop()
      for to in E[x]:
          if D2[to] == -1:
              D2[to] = D2[x] + 1
              Q.append(to)
  
  if MAX % 2 == 0:
      for i in range(N + 1):
          if D[i] == MAX // 2 and D2[i] == MAX // 2:
              c = i
              break
  
      TOP_SORT = []
  
      Q = [c]
      D = [-1] * (N + 1)
      P = [-1] * (N + 1)
      D[c] = 0
      while Q:
          x = Q.pop()
          TOP_SORT.append(x)
          for to in E[x]:
              if D[to] == -1:
                  D[to] = D[x] + 1
                  Q.append(to)
                  P[to] = x
  
      DP = [[[0, 0, 0] for i in range(3)] for i in range(N + 1)]
      # DP[x][p][m]で, plusのものが0個, 1個, 2個以上, minusのものが0個, 1個, 2個以上
  
      for x in TOP_SORT[::-1]:
          if D[x] == MAX // 2:
              DP[x][1][1] = 1
  
          elif len(E[x]) == 1:
              DP[x][0][0] = 1
  
          else:
              for to in E[x]:
                  if to == P[x]:
                      continue
  
                  X = [[0, 0, 0] for i in range(3)]
                  for i in range(3):
                      for j in range(3):
                          X[0][0] += DP[to][i][j]
                          X[i][0] += DP[to][i][j]
                          X[0][j] += DP[to][i][j]
  
                  if DP[x] == [[0, 0, 0] for i in range(3)]:
                      DP[x] = X
  
                  else:
                      Y = [[0, 0, 0] for i in range(3)]
  
                      for i in range(3):
                          for j in range(3):
                              for k in range(3):
                                  for l in range(3):
                                      Y[min(2, i + k)][min(2, j + l)] = (
                                          Y[min(2, i + k)][min(2, j + l)]
                                          + X[i][j] * DP[x][k][l]
                                      ) % mod
  
                      DP[x] = Y
  
      # print(DP)
      print(DP[c][1][1] * pow(2, mod - 2, mod) % mod)
  
  else:
      for i in range(N + 1):
          if D[i] == MAX // 2 and D2[i] == MAX // 2 + 1:
              c1 = i
          elif D[i] == MAX // 2 + 1 and D2[i] == MAX // 2:
              c2 = i
  
      TOP_SORT = []
  
      Q = [c1, c2]
      D = [-1] * (N + 1)
      P = [-1] * (N + 1)
      D[c1] = 0
      D[c2] = 0
  
      while Q:
          x = Q.pop()
          TOP_SORT.append(x)
          for to in E[x]:
              if D[to] == -1:
                  D[to] = D[x] + 1
                  Q.append(to)
                  P[to] = x
  
      DP = [[[0, 0, 0] for i in range(3)] for i in range(N + 1)]
      # DP[x][p][m]で, plusのものが0個, 1個, 2個以上, minusのものが0個, 1個, 2個以上
  
      for x in TOP_SORT[::-1]:
          if D[x] == MAX // 2:
              DP[x][1][1] = 1
  
          elif len(E[x]) == 1:
              DP[x][0][0] = 1
  
          else:
              for to in E[x]:
                  if to == P[x]:
                      continue
  
                  X = [[0, 0, 0] for i in range(3)]
                  for i in range(3):
                      for j in range(3):
                          X[0][0] += DP[to][i][j]
                          X[i][0] += DP[to][i][j]
                          X[0][j] += DP[to][i][j]
  
                  if DP[x] == [[0, 0, 0] for i in range(3)]:
                      DP[x] = X
  
                  else:
                      Y = [[0, 0, 0] for i in range(3)]
  
                      for i in range(3):
                          for j in range(3):
                              for k in range(3):
                                  for l in range(3):
                                      Y[min(2, i + k)][min(2, j + l)] = (
                                          Y[min(2, i + k)][min(2, j + l)]
                                          + X[i][j] * DP[x][k][l]
                                      ) % mod
  
                      DP[x] = Y
  
      # print(DP)
      print(DP[c2][1][1] * pow(2, mod - 2, mod) % mod)
  
problem_description: Statement
  
  We have a tree G with N vertices numbered 1 to N. The i-th edge of G connects
  Vertex a_i and Vertex b_i.
  
  Consider adding zero or more edges in G, and let H be the graph resulted.
  
  Find the number of graphs H that satisfy the following conditions, modulo
  998244353.
  
    * H does not contain self-loops or multiple edges.
    * The diameters of G and H are equal.
    * For every pair of vertices in H that is not directly connected by an edge, the addition of an edge directly connecting them would reduce the diameter of the graph.
samples: [{"input": "6\n    1 6\n    2 1\n    5 2\n    3 4\n    2 3", "output": "3\n    \n\nFor example, adding the edges (1, 5), (3, 5) in G satisfies the conditions.\n\n* * *"}, {"input": "3\n    1 2\n    2 3", "output": "1\n    \n\nThe only graph H that satisfies the conditions is G.\n\n* * *"}, {"input": "9\n    1 2\n    2 3\n    4 2\n    1 7\n    6 1\n    2 5\n    5 9\n    6 8", "output": "27\n    \n\n* * *"}, {"input": "19\n    2 4\n    15 8\n    1 16\n    1 3\n    12 19\n    1 18\n    7 11\n    11 15\n    12 9\n    1 6\n    7 14\n    18 2\n    13 12\n    13 5\n    16 13\n    7 1\n    11 10\n    7 17", "output": "78732"}]