Language: C++

#define fi first
#define se second
#define fil(a,b) memset((a),(b),sizeof(a))
#define cl(a) fil(a,0)
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++)
#define rep(i,a,b) for (int i=(a),_ed=(b);i<_ed;i++)
#define per(i,a,b) for (int i=(b)-1,_ed=(a);i>=_ed;i--)
#define forg(i,gu) for (int i=gu;~i;i=e[i].next)
#define pw(x) ((ll(1))<<(x))
#define upmo(a,b) (((a)=((a)+(b))%mo)<0?(a)+=mo:(a))
#define mmo(a,b) (((a)=1ll*(a)*(b)%mo)<0?(a)+=mo:(a))
void getre(){int x=0;printf("%d\n",1/x);}
void gettle(){int res=1;while(1)res<<=1;printf("%d\n",res);}
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
template<typename T,typename S>inline bool upmin(T&a,const S&b){return a>b?a=b,1:0;}
template<typename T,typename S>inline bool upmax(T&a,const S&b){return a<b?a=b,1:0;}
template<typename N,typename PN>inline N flo(N a,PN b){return a>=0?a/b:-((-a-1)/b)-1;}
template<typename N,typename PN>inline N cei(N a,PN b){return a>0?(a-1)/b+1:-(-a/b);}
template<typename N>N gcd(N a,N b){return b?gcd(b,a%b):a;}
template<typename N>inline int sgn(N a){return a>0?1:(a<0?-1:0);}
#if ( ( _WIN32 || __WIN32__ ) && __cplusplus < 201103L)
#define lld "%I64d"
#else
#define lld "%lld"
#endif
inline void gn(long long&x){
	int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');
	c=='-'?(sg=-1,x=0):(x=c-'0');
	while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;
}
inline void gn(int&x){long long t;gn(t);x=t;}
inline void gn(unsigned long long&x){long long t;gn(t);x=t;}
inline void gn(double&x){double t;scanf("%lf",&t);x=t;}
inline void gn(long double&x){double t;scanf("%lf",&t);x=t;}
inline void gs(char *s){scanf("%s",s);}
inline void gc(char &c){while((c=getchar())>126 || c<33);}
inline void pc(char c){putchar(c);}
#ifdef JCVB
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif
typedef long long ll;
typedef double db;
inline ll sqr(ll a){return a*a;}
inline db sqrf(db a){return a*a;}
const int inf=0x3f3f3f3f;
//const ll inf=0x3f3f3f3f3f3f3f3fll;
const db pi=3.14159265358979323846264338327950288L;
const db eps=1e-6;
//const int mo=0;
//int qp(int a,ll b){int n=1;do{if(b&1)n=1ll*n*a%mo;a=1ll*a*a%mo;}while(b>>=1);return n;}

int n;
vi chd[11111];

int qu[11111];
int d[11111];
int dis[11111];
int bfs(int u){
	int p=0,q=0;
	rep(i,1,n+1)dis[i]=-1;
	qu[q++]=u;
	dis[u]=0;
	while(p!=q){
		int u=qu[p++];
		for (auto v:chd[u]) {
			if(dis[v]!=-1)continue;
			dis[v]=dis[u]+1;
			qu[q++]=v;
		}
	}
}

vi leaf;

int needdeg[555];
int bfs2(){
	int p=0,q=0;
	rep(i,1,n+1)dis[i]=-1;
	rep(u,1,n+1)if(chd[u].size()==1) {
		dis[u]=0;
		qu[q++]=u;
	}
	while(p!=q){
		int u=qu[p++];
		for (auto v:chd[u]) {
			if(dis[v]!=-1)continue;
			dis[v]=dis[u]+1;
			qu[q++]=v;
		}
	}
}

ll gao() {
	cl(needdeg);
	leaf.clear();
	bfs(1);
	int u=1;
	rep(i,1,n+1)if(dis[i]>dis[u])u=i;
	bfs(u);
	int d=0;
	rep(i,1,n+1)upmax(d,dis[i]);
	rep(i,1,n+1)if(chd[i].size()==1) {
		leaf.pb(i);
	}
	int idtot=n;
	for (auto le:leaf) {
		bfs(le);
		int ma=0;
		rep(i,1,n+1)upmax(ma,dis[i]);
		int del = d - ma;
		int las=le;
		rep(j,0,del) {
			int ne = ++idtot;
			chd[las].pb(ne);
			chd[ne].pb(las);
			las=ne;
		}
	}
	n=idtot;
	bfs2();
	rep(u,1,n+1) {
		upmax(needdeg[dis[u]],chd[u].size());
	}
	ll ans=1;
	if(d%2==1) {
		rep(i,1,d/2+1)
			ans *= needdeg[i]-1;

		ans*=2;
	}else{
		rep(i,1,d/2)
			ans*=needdeg[i]-1;
		ans*=needdeg[d/2];
	}
	return ans;
}
int oldn;

vi  oldchd[111];
void clea() {
	rep(i,1,n+1)chd[i].clear();
	rep(i,1,oldn+1)chd[i]=oldchd[i];
	n=oldn;
}
int main()
{
	gn(n);
	oldn=n;
	rep(i,1,n){
		int u,v;
		gn(u);gn(v);
		chd[u].pb(v);
		chd[v].pb(u);
	}
	rep(i,1,n+1)oldchd[i]=chd[i];
	bfs(1);
	int u=1;
	rep(i,1,n+1)if(dis[i]>dis[u])u=i;
	bfs(u);
	int d=0;
	rep(i,1,n+1)upmax(d,dis[i]);
	rep(i,1,n+1)if(chd[i].size()==1) {
		leaf.pb(i);
	}
	int idtot=n;
	for (auto le:leaf) {
		bfs(le);
		int ma=0;
		rep(i,1,n+1)upmax(ma,dis[i]);
		int del = d - ma;
		int las=le;
		rep(j,0,del) {
			int ne = ++idtot;
			chd[las].pb(ne);
			chd[ne].pb(las);
			las=ne;
		}
	}
	n=idtot;
	bfs2();
	rep(u,1,n+1) {
		upmax(needdeg[dis[u]],chd[u].size());
	}
	ll ans=1;
	if(d%2==1) {
		rep(i,1,d/2+1)
			ans *= needdeg[i]-1;

		ans*=2;
	}else{
		rep(i,1,d/2)
			ans*=needdeg[i]-1;
		ans*=needdeg[d/2];
		rep(u,1,oldn+1){
			clea();
			chd[u].pb(n+1);
			chd[n+1].pb(u);
			n++;
			upmin(ans,gao());
		}
	}
	cout<<d/2+1<<" ";
	cout<<ans<<endl;
	return 0;

}



Compiler output:
a.cc: In function 'void getre()':
a.cc:14:22: error: 'printf' was not declared in this scope
   14 | void getre(){int x=0;printf("%d\n",1/x);}
      |                      ^~~~~~
a.cc:1:1: note: 'printf' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
  +++ |+#include <cstdio>
    1 | #define fi first
a.cc: In function 'void gettle()':
a.cc:15:41: error: 'printf' was not declared in this scope
   15 | void gettle(){int res=1;while(1)res<<=1;printf("%d\n",res);}
      |                                         ^~~~~~
a.cc:15:41: note: 'printf' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
a.cc: At global scope:
a.cc:16:9: error: 'pair' does not name a type
   16 | typedef pair<int,int> pii;
      |         ^~~~
a.cc:17:9: error: 'vector' does not name a type
   17 | typedef vector<int> vi;
      |         ^~~~~~
a.cc:18:9: error: 'vector' does not name a type
   18 | typedef vector<pii> vpii;
      |         ^~~~~~
a.cc: In function 'void gn(long long int&)':
a.cc:31:35: error: 'getchar' was not declared in this scope
   31 |         int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');
      |                                   ^~~~~~~
a.cc:31:35: note: 'getchar' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
a.cc:33:18: error: 'getchar' was not declared in this scope
   33 |         while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;
      |                  ^~~~~~~
a.cc:33:18: note: 'getchar' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
a.cc: In function 'void gn(double&)':
a.cc:37:35: error: 'scanf' was not declared in this scope
   37 | inline void gn(double&x){double t;scanf("%lf",&t);x=t;}
      |                                   ^~~~~
a.cc: In function 'void gn(long double&)':
a.cc:38:40: error: 'scanf' was not declared in this scope
   38 | inline void gn(long double&x){double t;scanf("%lf",&t);x=t;}
      |                                        ^~~~~
a.cc: In function 'void gs(char*)':
a.cc:39:25: error: 'scanf' was not declared in this scope
   39 | inline void gs(char *s){scanf("%s",s);}
      |                         ^~~~~
a.cc: In function 'void gc(char&)':
a.cc:40:34: error: 'getchar' was not declared in this scope
   40 | inline void gc(char &c){while((c=getchar())>126 || c<33);}
      |                                  ^~~~~~~
a.cc:40:34: note: 'getchar' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
a.cc: In function 'void pc(char)':
a.cc:41:24: error: 'putchar' was not declared in this scope; did you mean 'char'?
   41 | inline void pc(char c){putchar(c);}
      |                        ^~~~~~~
      |                        char
a.cc: At global scope:
a.cc:59:1: error: 'vi' does not name a type; did you mean 'fi'?
   59 | vi chd[11111];
      | ^~
      | fi
a.cc: In function 'int bfs(int)':
a.cc:71:29: error: 'chd' was not declared in this scope
   71 |                 for (auto v:chd[u]) {
      |                             ^~~
a.cc:77:1: warning: no return statement in function returning non-void [-Wreturn-type]
   77 | }
      | ^
a.cc: At global scope:
a.cc:79:1: error: 'vi' does not name a type; did you mean 'fi'?
   79 | vi leaf;
      | ^~
      | fi
a.cc: In function 'int bfs2()':
a.cc:85:24: error: 'chd' was not declared in this scope
   85 |         rep(u,1,n+1)if(chd[u].size()==1) {
      |                        ^~~
a.cc:91:29: error: 'chd' was not declared in this scope
   91 |                 for (auto v:chd[u]) {
      |                             ^~~
a.cc:97:1: warning: no return statement in function returning non-void [-Wreturn-type]
   97 | }
      | ^
a.cc: In function 'll gao()':
a.cc:3:18: error: 'memset' was not declared in this scope
    3 | #define fil(a,b) memset((a),(b),sizeof(a))
      |                  ^~~~~~
a.cc:4:15: note: in expansion of macro 'fil'
    4 | #define cl(a) fil(a,0)
      |               ^~~
a.cc:100:9: note: in expansion of macro 'cl'
  100 |         cl(needdeg);
      |         ^~
a.cc:1:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
  +++ |+#include <cstring>
    1 | #define fi first
a.cc:101:9: error: 'leaf' was not declared in this scope
  101 |         leaf.clear();
      |         ^~~~
a.cc:108:24: error: 'chd' was not declared in this scope
  108 |         rep(i,1,n+1)if(chd[i].size()==1) {
      |                        ^~~
a.cc:120:25: error: 'chd' was not declared in this scope
  120 |                         chd[las].pb(ne);
      |                         ^~~
a.cc:128:39: error: 'chd' was not declared in this scope
  128 |                 upmax(needdeg[dis[u]],chd[u].size());
      |                                       ^~~
a.cc: At global scope:
a.cc:145:1: error: 'vi' does not name a type; did you mean 'fi'?
  145 | vi  oldchd[111];
      | ^~
      | fi
a.cc: In function 'void clea()':
a.cc:147:21: error: 'chd' was not declared in this scope
  147 |         rep(i,1,n+1)chd[i].clear();
      |                     ^~~
a.cc:148:24: error: 'chd' was not declared in this scope
  148 |         rep(i,1,oldn+1)chd[i]=oldchd[i];
      |                        ^~~
a.cc:148:31: error: 'oldchd' was not declared in this scope
  148 |         rep(i,1,oldn+1)chd[i]=oldchd[i];
      |                               ^~~~~~
a.cc: In function 'int main()':
a.cc:158:17: error: 'chd' was not declared in this scope
  158 |                 chd[u].pb(v);
      |                 ^~~
a.cc:161:21: error: 'oldchd' was not declared in this scope
  161 |         rep(i,1,n+1)oldchd[i]=chd[i];
      |                     ^~~~~~
a.cc:161:31: error: 'chd' was not declared in this scope
  161 |         rep(i,1,n+1)oldchd[i]=chd[i];
      |                               ^~~
a.cc:168:24: error: 'chd' was not declared in this scope
  168 |         rep(i,1,n+1)if(chd[i].size()==1) {
      |                        ^~~
a.cc:169:17: error: 'leaf' was not declared in this scope
  169 |                 leaf.pb(i);
      |                 ^~~~
a.cc:172:22: error: 'leaf' was not declared in this scope; did you mean 'le'?
  172 |         for (auto le:leaf) {
      |                      ^~~~
      |                      le
a.cc:180:25: error: 'chd' was not declared in this scope
  180 |                         chd[las].pb(ne);
      |                         ^~~
a.cc:188:39: error: 'chd' was not declared in this scope
  188 |                 upmax(needdeg[dis[u]],chd[u].size());
      |                                       ^~~
a.cc:202:25: error: 'chd' was not declared in this scope
  202 |                         chd[u].pb(n+1);
      |                         ^~~
a.cc:208:9: error: 'cout' was not declared in this scope
  208 |         cout<<d/2+1<<" ";
      |         ^~~~
a.cc:209:20: error: 'endl' was not declared in this scope
  209 |         cout<<ans<<endl;
      |                    ^~~~