#include <iostream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <cstring>
#include <iomanip>
#include <set>
#include <sstream>
#include <ctime>
#define rust(a, b, c, d) sqrt(sqr(a - c) + sqr(b - d))
#define sqr(a) (a)*(a)
#define p_b push_back
#define m_p make_pair
#define fi first
#define se second
#define endl "\n"
typedef long long ll;
typedef long double ld;
const int MAXINT = 2147483640;
const ll MAXLL = 9223372036854775800LL;
const ll MAXN = 1123456;
const ll MOD = 1123456769;
using namespace std;
vector < int > ss[MAXN];
vector < pair < int, int > > ways[MAXN];
vector < int > s[MAXN];
int len[MAXN];
void dfs(int v, int pr){
ways[v].clear();
len[v] = 0;
s[v].clear();
for (int i = 0; i < ss[v].size(); i++) if (ss[v][i] != pr) {
dfs(ss[v][i], v);
len[v] = max(len[v], len[ss[v][i]] + 1);
s[v].p_b(len[ss[v][i]] + 1);
}
sort(s[v].begin(), s[v].end());
for (int i = 0; i < ss[v].size(); i++) if (ss[v][i] != pr) {
int it = s[v].size() - 1;
int x = ss[v][i];
if (len[x] + 1 == s[v][it]) --it;
int y = 0;
if (s[v].size() > 1) y = s[v][it];
for (int j = 0; j < ways[x].size(); j++) ways[v].p_b(m_p(ways[x][j].fi + 1, max(ways[x][j].se, y)));
}
if (ss[v].size() == 1 && pr != 0) ways[v].p_b(m_p(0, 0)), len[v] = 0;
}
int main()
{
// freopen("road.in", "r", stdin);
// freopen("road.out", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(0);
srand(time(0));
int n, m, i, j, x, y;
cin >> n;
for (i = 1; i < n; i++){
cin >> x >> y;
ss[x].p_b(y);
ss[y].p_b(x);
}
vector < ll > ans;
for (i = 1; i <= n; i++) if (ss[i].size() == 1) {
dfs(i, 0);
for (j = 0; j < ways[i].size(); j++) ans.p_b(ll(ways[i][j].fi) * ways[i][j].se);
}
sort(ans.begin(), ans.end());
if (ans.size()) x = ans.back(); else x = 0;
y = 0;
for (i = ans.size() - 1; i >= 0; i--) if (ans[i] == x) ++y;
cout << x << " " << y / 2 << endl;
return 0;
}
Compilation message
road.cpp: In function 'void dfs(int, int)':
road.cpp:40:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < ss[v].size(); i++) if (ss[v][i] != pr) {
^
road.cpp:46:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < ss[v].size(); i++) if (ss[v][i] != pr) {
^
road.cpp:52:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < ways[x].size(); j++) ways[v].p_b(m_p(ways[x][j].fi + 1, max(ways[x][j].se, y)));
^
road.cpp: In function 'int main()':
road.cpp:73:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (j = 0; j < ways[i].size(); j++) ans.p_b(ll(ways[i][j].fi) * ways[i][j].se);
^
road.cpp:63:12: warning: unused variable 'm' [-Wunused-variable]
int n, m, i, j, x, y;
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
85564 KB |
Output is correct |
2 |
Correct |
23 ms |
85564 KB |
Output is correct |
3 |
Correct |
19 ms |
85564 KB |
Output is correct |
4 |
Correct |
23 ms |
85564 KB |
Output is correct |
5 |
Correct |
23 ms |
85564 KB |
Output is correct |
6 |
Correct |
19 ms |
85564 KB |
Output is correct |
7 |
Correct |
23 ms |
85564 KB |
Output is correct |
8 |
Correct |
29 ms |
85564 KB |
Output is correct |
9 |
Correct |
16 ms |
85564 KB |
Output is correct |
10 |
Correct |
16 ms |
85564 KB |
Output is correct |
11 |
Correct |
26 ms |
85700 KB |
Output is correct |
12 |
Correct |
23 ms |
85700 KB |
Output is correct |
13 |
Correct |
16 ms |
85700 KB |
Output is correct |
14 |
Correct |
23 ms |
85704 KB |
Output is correct |
15 |
Correct |
13 ms |
85564 KB |
Output is correct |
16 |
Correct |
23 ms |
85564 KB |
Output is correct |
17 |
Correct |
19 ms |
85564 KB |
Output is correct |
18 |
Correct |
29 ms |
85564 KB |
Output is correct |
19 |
Correct |
29 ms |
85564 KB |
Output is correct |
20 |
Correct |
23 ms |
85564 KB |
Output is correct |
21 |
Correct |
16 ms |
85564 KB |
Output is correct |
22 |
Correct |
26 ms |
85564 KB |
Output is correct |
23 |
Correct |
19 ms |
85564 KB |
Output is correct |
24 |
Correct |
29 ms |
85880 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
85564 KB |
Output is correct |
2 |
Correct |
23 ms |
85564 KB |
Output is correct |
3 |
Correct |
19 ms |
85564 KB |
Output is correct |
4 |
Correct |
23 ms |
85564 KB |
Output is correct |
5 |
Correct |
23 ms |
85564 KB |
Output is correct |
6 |
Correct |
19 ms |
85564 KB |
Output is correct |
7 |
Correct |
23 ms |
85564 KB |
Output is correct |
8 |
Correct |
29 ms |
85564 KB |
Output is correct |
9 |
Correct |
16 ms |
85564 KB |
Output is correct |
10 |
Correct |
16 ms |
85564 KB |
Output is correct |
11 |
Correct |
26 ms |
85700 KB |
Output is correct |
12 |
Correct |
23 ms |
85700 KB |
Output is correct |
13 |
Correct |
16 ms |
85700 KB |
Output is correct |
14 |
Correct |
23 ms |
85704 KB |
Output is correct |
15 |
Correct |
13 ms |
85564 KB |
Output is correct |
16 |
Correct |
23 ms |
85564 KB |
Output is correct |
17 |
Correct |
19 ms |
85564 KB |
Output is correct |
18 |
Correct |
29 ms |
85564 KB |
Output is correct |
19 |
Correct |
29 ms |
85564 KB |
Output is correct |
20 |
Correct |
23 ms |
85564 KB |
Output is correct |
21 |
Correct |
16 ms |
85564 KB |
Output is correct |
22 |
Correct |
26 ms |
85564 KB |
Output is correct |
23 |
Correct |
19 ms |
85564 KB |
Output is correct |
24 |
Correct |
29 ms |
85880 KB |
Output is correct |
25 |
Correct |
1169 ms |
182808 KB |
Output is correct |
26 |
Correct |
1076 ms |
182780 KB |
Output is correct |
27 |
Correct |
1036 ms |
182676 KB |
Output is correct |
28 |
Correct |
1063 ms |
182752 KB |
Output is correct |
29 |
Execution timed out |
2000 ms |
145848 KB |
Execution timed out |
30 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
85564 KB |
Output is correct |
2 |
Correct |
23 ms |
85564 KB |
Output is correct |
3 |
Correct |
19 ms |
85564 KB |
Output is correct |
4 |
Correct |
23 ms |
85564 KB |
Output is correct |
5 |
Correct |
23 ms |
85564 KB |
Output is correct |
6 |
Correct |
19 ms |
85564 KB |
Output is correct |
7 |
Correct |
23 ms |
85564 KB |
Output is correct |
8 |
Correct |
29 ms |
85564 KB |
Output is correct |
9 |
Correct |
16 ms |
85564 KB |
Output is correct |
10 |
Correct |
16 ms |
85564 KB |
Output is correct |
11 |
Correct |
26 ms |
85700 KB |
Output is correct |
12 |
Correct |
23 ms |
85700 KB |
Output is correct |
13 |
Correct |
16 ms |
85700 KB |
Output is correct |
14 |
Correct |
23 ms |
85704 KB |
Output is correct |
15 |
Correct |
13 ms |
85564 KB |
Output is correct |
16 |
Correct |
23 ms |
85564 KB |
Output is correct |
17 |
Correct |
19 ms |
85564 KB |
Output is correct |
18 |
Correct |
29 ms |
85564 KB |
Output is correct |
19 |
Correct |
29 ms |
85564 KB |
Output is correct |
20 |
Correct |
23 ms |
85564 KB |
Output is correct |
21 |
Correct |
16 ms |
85564 KB |
Output is correct |
22 |
Correct |
26 ms |
85564 KB |
Output is correct |
23 |
Correct |
19 ms |
85564 KB |
Output is correct |
24 |
Correct |
29 ms |
85880 KB |
Output is correct |
25 |
Correct |
1169 ms |
182808 KB |
Output is correct |
26 |
Correct |
1076 ms |
182780 KB |
Output is correct |
27 |
Correct |
1036 ms |
182676 KB |
Output is correct |
28 |
Correct |
1063 ms |
182752 KB |
Output is correct |
29 |
Execution timed out |
2000 ms |
145848 KB |
Execution timed out |
30 |
Halted |
0 ms |
0 KB |
- |