#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#define MOD 1000000007
#define inf 1e18
#define fi first
#define se second
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define sz(a) ((int)(a).size())
#define endl '\n'
#define pi 3.14159265359
#define TASKNAME "hardroute"
using namespace std;
template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; }
template<typename T> bool minimize(T &res, const T &val) { if (res > val){ res = val; return true; }; return false; }
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
const int MAXN = 3e5 + 9;
int n;
ii edge[MAXN];
vector<int> g[MAXN];
namespace subtask2{
bool check(){
return true;
}
int dp[MAXN], deg[MAXN], mx[MAXN], ans = 0, cnt_ans = 0;
void dfs1(int u, int p){
dp[u] = 0;
mx[u] = 0;
for(auto id: g[u]){
int v = edge[id].se + edge[id].fi - u;
if (v == p) continue;
dfs1(v, u);
maximize(dp[u], dp[v] + 1);
}
}
void dfs2(int u, int p, int d, int d_out){
if (deg[u] == 1 and d != 0) {
if (maximize(ans, d * d_out)) cnt_ans = 1;
else if (ans == d * d_out) cnt_ans++;
}
int mxd = 0;
for(auto id: g[u]){
int v = edge[id].se + edge[id].fi - u;
if (v == p) continue;
maximize(mx[v], mxd);
maximize(mxd, dp[v] + 1);
}
reverse(g[u].begin(), g[u].end());
mxd = 0;
for(auto id: g[u]){
int v = edge[id].se + edge[id].fi - u;
if (v == p) continue;
maximize(mx[v], mxd);
maximize(mxd, dp[v] + 1);
}
for(auto id: g[u]){
int v = edge[id].se + edge[id].fi - u;
if (v == p) continue;
dfs2(v, u, d + 1, max(d_out, mx[v]));
}
}
void solve(){
FOR(i, 1, n - 1){
deg[edge[i].fi]++;
deg[edge[i].se]++;
}
FOR(i, 1, n){
if (deg[i] == 1){
dfs1(i, -1);
dfs2(i, -1, 0, 0);
}
}
cout << ans << ' ' << cnt_ans / 2<< endl;
}
}
main()
{
fast;
if (fopen(TASKNAME".inp","r")){
freopen(TASKNAME".inp","r",stdin);
freopen(TASKNAME".out","w",stdout);
}
cin >> n;
FOR(i, 1, n - 1){
cin >> edge[i].fi >> edge[i].se;
g[edge[i].fi].pb(i);
g[edge[i].se].pb(i);
}
if (subtask2::check()) return subtask2::solve(), 0;
}
/**
Warning:
Đọc sai đề???
Cận lmao
Code imple thiếu case nào không.
Limit.
**/
컴파일 시 표준 에러 (stderr) 메시지
road.cpp:90:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
90 | main()
| ^~~~
road.cpp: In function 'int main()':
road.cpp:94:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
94 | freopen(TASKNAME".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
road.cpp:95:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
95 | freopen(TASKNAME".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |