#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];
int len[MAXN];
void dfs(int v, int pr){
vector < int > s;
ways[v].clear();
len[v] = 0;
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.p_b(len[ss[v][i]] + 1);
}
sort(s.begin(), s.end());
for (int i = 0; i < ss[v].size(); i++) if (ss[v][i] != pr) {
int it = s.size() - 1;
int x = ss[v][i];
if (len[x] + 1 == s[it]) --it;
int y = 0;
if (s.size() > 1) y = s[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:39: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:45: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:51: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:72: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:62:12: warning: unused variable 'm' [-Wunused-variable]
int n, m, i, j, x, y;
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
59232 KB |
Output is correct |
2 |
Correct |
13 ms |
59232 KB |
Output is correct |
3 |
Correct |
13 ms |
59232 KB |
Output is correct |
4 |
Correct |
26 ms |
59232 KB |
Output is correct |
5 |
Correct |
16 ms |
59232 KB |
Output is correct |
6 |
Correct |
13 ms |
59232 KB |
Output is correct |
7 |
Correct |
13 ms |
59232 KB |
Output is correct |
8 |
Correct |
16 ms |
59232 KB |
Output is correct |
9 |
Correct |
16 ms |
59232 KB |
Output is correct |
10 |
Correct |
13 ms |
59232 KB |
Output is correct |
11 |
Correct |
16 ms |
59368 KB |
Output is correct |
12 |
Correct |
13 ms |
59368 KB |
Output is correct |
13 |
Correct |
16 ms |
59368 KB |
Output is correct |
14 |
Correct |
23 ms |
59368 KB |
Output is correct |
15 |
Correct |
16 ms |
59232 KB |
Output is correct |
16 |
Correct |
9 ms |
59232 KB |
Output is correct |
17 |
Correct |
23 ms |
59232 KB |
Output is correct |
18 |
Correct |
9 ms |
59232 KB |
Output is correct |
19 |
Correct |
16 ms |
59232 KB |
Output is correct |
20 |
Correct |
26 ms |
59232 KB |
Output is correct |
21 |
Correct |
16 ms |
59232 KB |
Output is correct |
22 |
Correct |
16 ms |
59232 KB |
Output is correct |
23 |
Correct |
16 ms |
59232 KB |
Output is correct |
24 |
Correct |
29 ms |
59548 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
59232 KB |
Output is correct |
2 |
Correct |
13 ms |
59232 KB |
Output is correct |
3 |
Correct |
13 ms |
59232 KB |
Output is correct |
4 |
Correct |
26 ms |
59232 KB |
Output is correct |
5 |
Correct |
16 ms |
59232 KB |
Output is correct |
6 |
Correct |
13 ms |
59232 KB |
Output is correct |
7 |
Correct |
13 ms |
59232 KB |
Output is correct |
8 |
Correct |
16 ms |
59232 KB |
Output is correct |
9 |
Correct |
16 ms |
59232 KB |
Output is correct |
10 |
Correct |
13 ms |
59232 KB |
Output is correct |
11 |
Correct |
16 ms |
59368 KB |
Output is correct |
12 |
Correct |
13 ms |
59368 KB |
Output is correct |
13 |
Correct |
16 ms |
59368 KB |
Output is correct |
14 |
Correct |
23 ms |
59368 KB |
Output is correct |
15 |
Correct |
16 ms |
59232 KB |
Output is correct |
16 |
Correct |
9 ms |
59232 KB |
Output is correct |
17 |
Correct |
23 ms |
59232 KB |
Output is correct |
18 |
Correct |
9 ms |
59232 KB |
Output is correct |
19 |
Correct |
16 ms |
59232 KB |
Output is correct |
20 |
Correct |
26 ms |
59232 KB |
Output is correct |
21 |
Correct |
16 ms |
59232 KB |
Output is correct |
22 |
Correct |
16 ms |
59232 KB |
Output is correct |
23 |
Correct |
16 ms |
59232 KB |
Output is correct |
24 |
Correct |
29 ms |
59548 KB |
Output is correct |
25 |
Correct |
1356 ms |
156136 KB |
Output is correct |
26 |
Correct |
1309 ms |
156236 KB |
Output is correct |
27 |
Correct |
1303 ms |
156252 KB |
Output is correct |
28 |
Correct |
1356 ms |
156216 KB |
Output is correct |
29 |
Execution timed out |
2000 ms |
119636 KB |
Execution timed out |
30 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
59232 KB |
Output is correct |
2 |
Correct |
13 ms |
59232 KB |
Output is correct |
3 |
Correct |
13 ms |
59232 KB |
Output is correct |
4 |
Correct |
26 ms |
59232 KB |
Output is correct |
5 |
Correct |
16 ms |
59232 KB |
Output is correct |
6 |
Correct |
13 ms |
59232 KB |
Output is correct |
7 |
Correct |
13 ms |
59232 KB |
Output is correct |
8 |
Correct |
16 ms |
59232 KB |
Output is correct |
9 |
Correct |
16 ms |
59232 KB |
Output is correct |
10 |
Correct |
13 ms |
59232 KB |
Output is correct |
11 |
Correct |
16 ms |
59368 KB |
Output is correct |
12 |
Correct |
13 ms |
59368 KB |
Output is correct |
13 |
Correct |
16 ms |
59368 KB |
Output is correct |
14 |
Correct |
23 ms |
59368 KB |
Output is correct |
15 |
Correct |
16 ms |
59232 KB |
Output is correct |
16 |
Correct |
9 ms |
59232 KB |
Output is correct |
17 |
Correct |
23 ms |
59232 KB |
Output is correct |
18 |
Correct |
9 ms |
59232 KB |
Output is correct |
19 |
Correct |
16 ms |
59232 KB |
Output is correct |
20 |
Correct |
26 ms |
59232 KB |
Output is correct |
21 |
Correct |
16 ms |
59232 KB |
Output is correct |
22 |
Correct |
16 ms |
59232 KB |
Output is correct |
23 |
Correct |
16 ms |
59232 KB |
Output is correct |
24 |
Correct |
29 ms |
59548 KB |
Output is correct |
25 |
Correct |
1356 ms |
156136 KB |
Output is correct |
26 |
Correct |
1309 ms |
156236 KB |
Output is correct |
27 |
Correct |
1303 ms |
156252 KB |
Output is correct |
28 |
Correct |
1356 ms |
156216 KB |
Output is correct |
29 |
Execution timed out |
2000 ms |
119636 KB |
Execution timed out |
30 |
Halted |
0 ms |
0 KB |
- |