#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


template<typename T,T MOD = 1000000007>
struct Mint{
  static constexpr T mod = MOD;
  T v;
  Mint():v(0){}
  Mint(signed v):v(v){}
  Mint(long long t){v=t%MOD;if(v<0) v+=MOD;}

  Mint pow(long long k){
    Mint res(1),tmp(v);
    while(k){
      if(k&1) res*=tmp;
      tmp*=tmp;
      k>>=1;
    }
    return res;
  }

  static Mint add_identity(){return Mint(0);}
  static Mint mul_identity(){return Mint(1);}

  Mint inv(){return pow(MOD-2);}

  Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;}
  Mint& operator/=(Mint a){return (*this)*=a.inv();}

  Mint operator+(Mint a) const{return Mint(v)+=a;}
  Mint operator-(Mint a) const{return Mint(v)-=a;}
  Mint operator*(Mint a) const{return Mint(v)*=a;}
  Mint operator/(Mint a) const{return Mint(v)/=a;}

  Mint operator-() const{return v?Mint(MOD-v):Mint(v);}

  bool operator==(const Mint a)const{return v==a.v;}
  bool operator!=(const Mint a)const{return v!=a.v;}
  bool operator <(const Mint a)const{return v <a.v;}

  static Mint comb(long long n,int k){
    Mint num(1),dom(1);
    for(int i=0;i<k;i++){
      num*=Mint(n-i);
      dom*=Mint(i+1);
    }
    return num/dom;
  }
};
template<typename T,T MOD> constexpr T Mint<T, MOD>::mod;
template<typename T,T MOD>
ostream& operator<<(ostream &os,Mint<T, MOD> m){os<<m.v;return os;}


template<typename F>
struct FixPoint : F{
  FixPoint(F&& f):F(forward<F>(f)){}
  template<typename... Args>
  decltype(auto) operator()(Args&&... args) const{
    return F::operator()(*this,forward<Args>(args)...);
  }
};
template<typename F>
inline decltype(auto) MFP(F&& f){
  return FixPoint<F>{forward<F>(f)};
}

struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;

//INSERT ABOVE HERE
signed main(){
  using M = Mint<int, 998244353>;
  auto solve2=
    [&](vector< vector<int> > G){
      int n=G.size();
      vector<int> dep(n),par(n);
      auto dfs1=
        MFP([&](auto dfs,int v,int p,int d)->void{
              dep[v]=d;
              par[v]=p;
              for(int u:G[v])
                if(u!=p) dfs(u,v,d+1);
            });
      dfs1(0,-1,0);
      int s=max_element(dep.begin(),dep.end())-dep.begin();
      dfs1(s,-1,0);
      int t=max_element(dep.begin(),dep.end())-dep.begin();
      int len=dep[t];

      vector<int> vs;
      vs.emplace_back(t);
      while(t!=s){
        t=par[t];
        vs.emplace_back(t);
      }

      int cen=vs[vs.size()/2];
      if(len&1){
        int x=vs[len/2],y=vs[len/2+1];
        for(int &z:G[x])
          if(z==y) swap(z,G[x].back());
        for(int &z:G[y])
          if(z==x) swap(z,G[y].back());
        G[x].back()=n;
        G[y].back()=n;
        G.emplace_back();
        G[n].emplace_back(x);
        G[n].emplace_back(y);
        cen=n++;
        len++;
      }

      vector<M> dp[3][3];
      for(int i=0;i<3;i++)
        for(int j=0;j<3;j++)
          dp[i][j].assign(n,0);

      MFP([&](auto dfs,int v,int p,int d)->void{
            dp[d*2==len][d*2==len][v]=1;
            for(int u:G[v]){
              if(u==p) continue;
              dfs(u,v,d+1);
              M nx[3][3]={};
              for(int i=0;i<3;i++){
                for(int j=0;j<3;j++){
                  for(int x=0;x<3;x++){
                    for(int y=0;y<3;y++){
                      for(int z=0;z<3;z++){
                        int ni=min(i+x*(z==0),2);
                        int nj=min(j+y*(z==1),2);
                        nx[ni][nj]+=dp[i][j][v]*dp[x][y][u];
                      }
                    }
                  }
                }
              }

              for(int i=0;i<3;i++)
                for(int j=0;j<3;j++)
                  dp[i][j][v]=nx[i][j];
            }
          })(cen,-1,0);

      return dp[1][1][cen]/2;
    };

  int n;
  cin>>n;
  vector< vector<int> > G(n);
  for(int i=1;i<n;i++){
    int x,y;
    cin>>x>>y;
    x--;y--;
    G[x].emplace_back(y);
    G[y].emplace_back(x);
  }

  cout<<solve2(G)<<endl;
  return 0;
}


Measured memory_bytes: 37032