#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#define X first
#define Y second
#define PB push_back
using namespace std;
typedef long long ll;
typedef pair < int , int > pii;
typedef pair < ll , ll > pll;
const int N = 1e6 + 500;
int n;
vector < pii > v[N];
pll dis[N];
ll cnt[N][3];
inline pll add(const pll &A, const pll &B){
return {(A.X > B.X ? A.X : B.X), A.Y * (A.X >= B.X) + B.Y * (B.X >= A.X)};
}
pll calc_dis(int x, int lst, int ind){
if(dis[2 * ind + (x < lst)].X != -1) return dis[2 * ind + (x < lst)];
pll ret = {0, 1};
for(pii y : v[x])
if(y.X != lst)
ret = add(ret, calc_dis(y.X, x, y.Y));
ret.X++;
return dis[2 * ind + (x < lst)] = ret;
}
ll ch(int n, int k){
int ret = 1;
for(int i = 0;i < k;i++)
ret *= (n - i), ret /= i + 1;
return ret;
}
int main(){
for(int i = 0;i < N;i++) dis[i].X = -1;
scanf("%d", &n);
for(int i = 1;i < n;i++){
int x, y; scanf("%d%d", &x, &y);
v[x].PB({y, i}), v[y].PB({x, i});
}
pll sol = {0, 0};
for(int i = 1;i <= n;i++){
vector < int > sus;
for(pii nxt : v[i]){
pll nw = calc_dis(nxt.X, i, nxt.Y);
sus.PB(nw.X);
cnt[nw.X][2] += nw.Y * cnt[nw.X][1];
cnt[nw.X][1] += nw.Y;
}
for(int j = 0;j < 3;j++)
for(int i = (int)sus.size() - 1; i ;i--)
if(sus[i - 1] < sus[i]) swap(sus[i], sus[i - 1]);
if((int)sus.size() > 2){
if(sus[0] > sus[1] && sus[1] > sus[2])
sol = add(sol, {(ll)(sus[1] + sus[2]) * sus[0], cnt[sus[1]][1] * cnt[sus[2]][1]});
else if(sus[0] == sus[1] && sus[1] == sus[2])
sol = add(sol, {(ll)(sus[1] + sus[2]) * sus[0], cnt[sus[0]][2]});
else if(sus[0] > sus[1])
sol = add(sol, {(ll)(sus[1] + sus[2]) * sus[0], cnt[sus[1]][2]});
else
sol = add(sol, {(ll)(sus[1] + sus[2]) * sus[0], cnt[sus[1]][2] & cnt[sus[2]][1]});
}
for(int x : sus){
cnt[x][1] = 0, cnt[x][2] = 0;
}
}
if(!sol.X) sol.Y++;
printf("%lld %lld\n", sol.X, sol.Y);
return 0;
}
Compilation message
road.cpp: In function 'int main()':
road.cpp:46:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
46 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
road.cpp:48:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
48 | int x, y; scanf("%d%d", &x, &y);
| ~~~~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
39500 KB |
Output is correct |
2 |
Correct |
21 ms |
39392 KB |
Output is correct |
3 |
Correct |
23 ms |
39456 KB |
Output is correct |
4 |
Correct |
22 ms |
39380 KB |
Output is correct |
5 |
Correct |
21 ms |
39444 KB |
Output is correct |
6 |
Correct |
22 ms |
39372 KB |
Output is correct |
7 |
Correct |
25 ms |
39364 KB |
Output is correct |
8 |
Correct |
21 ms |
39456 KB |
Output is correct |
9 |
Correct |
22 ms |
39456 KB |
Output is correct |
10 |
Correct |
21 ms |
39380 KB |
Output is correct |
11 |
Correct |
24 ms |
39408 KB |
Output is correct |
12 |
Correct |
24 ms |
39452 KB |
Output is correct |
13 |
Correct |
22 ms |
39420 KB |
Output is correct |
14 |
Correct |
22 ms |
39444 KB |
Output is correct |
15 |
Correct |
22 ms |
39384 KB |
Output is correct |
16 |
Correct |
21 ms |
39420 KB |
Output is correct |
17 |
Correct |
21 ms |
39432 KB |
Output is correct |
18 |
Correct |
22 ms |
39372 KB |
Output is correct |
19 |
Correct |
22 ms |
39408 KB |
Output is correct |
20 |
Correct |
23 ms |
39452 KB |
Output is correct |
21 |
Correct |
21 ms |
39372 KB |
Output is correct |
22 |
Correct |
25 ms |
39348 KB |
Output is correct |
23 |
Correct |
22 ms |
39396 KB |
Output is correct |
24 |
Correct |
23 ms |
39448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
39500 KB |
Output is correct |
2 |
Correct |
21 ms |
39392 KB |
Output is correct |
3 |
Correct |
23 ms |
39456 KB |
Output is correct |
4 |
Correct |
22 ms |
39380 KB |
Output is correct |
5 |
Correct |
21 ms |
39444 KB |
Output is correct |
6 |
Correct |
22 ms |
39372 KB |
Output is correct |
7 |
Correct |
25 ms |
39364 KB |
Output is correct |
8 |
Correct |
21 ms |
39456 KB |
Output is correct |
9 |
Correct |
22 ms |
39456 KB |
Output is correct |
10 |
Correct |
21 ms |
39380 KB |
Output is correct |
11 |
Correct |
24 ms |
39408 KB |
Output is correct |
12 |
Correct |
24 ms |
39452 KB |
Output is correct |
13 |
Correct |
22 ms |
39420 KB |
Output is correct |
14 |
Correct |
22 ms |
39444 KB |
Output is correct |
15 |
Correct |
22 ms |
39384 KB |
Output is correct |
16 |
Correct |
21 ms |
39420 KB |
Output is correct |
17 |
Correct |
21 ms |
39432 KB |
Output is correct |
18 |
Correct |
22 ms |
39372 KB |
Output is correct |
19 |
Correct |
22 ms |
39408 KB |
Output is correct |
20 |
Correct |
23 ms |
39452 KB |
Output is correct |
21 |
Correct |
21 ms |
39372 KB |
Output is correct |
22 |
Correct |
25 ms |
39348 KB |
Output is correct |
23 |
Correct |
22 ms |
39396 KB |
Output is correct |
24 |
Correct |
23 ms |
39448 KB |
Output is correct |
25 |
Correct |
24 ms |
39756 KB |
Output is correct |
26 |
Correct |
23 ms |
39756 KB |
Output is correct |
27 |
Correct |
25 ms |
39836 KB |
Output is correct |
28 |
Correct |
25 ms |
39852 KB |
Output is correct |
29 |
Correct |
25 ms |
39852 KB |
Output is correct |
30 |
Correct |
25 ms |
39776 KB |
Output is correct |
31 |
Correct |
25 ms |
39992 KB |
Output is correct |
32 |
Correct |
25 ms |
39752 KB |
Output is correct |
33 |
Correct |
28 ms |
39788 KB |
Output is correct |
34 |
Correct |
28 ms |
39856 KB |
Output is correct |
35 |
Correct |
25 ms |
39788 KB |
Output is correct |
36 |
Correct |
24 ms |
39756 KB |
Output is correct |
37 |
Correct |
25 ms |
39900 KB |
Output is correct |
38 |
Correct |
25 ms |
40012 KB |
Output is correct |
39 |
Correct |
25 ms |
39776 KB |
Output is correct |
40 |
Correct |
25 ms |
39664 KB |
Output is correct |
41 |
Correct |
24 ms |
39632 KB |
Output is correct |
42 |
Correct |
24 ms |
39608 KB |
Output is correct |
43 |
Correct |
28 ms |
39492 KB |
Output is correct |
44 |
Correct |
24 ms |
39540 KB |
Output is correct |
45 |
Correct |
27 ms |
39492 KB |
Output is correct |
46 |
Correct |
31 ms |
39508 KB |
Output is correct |
47 |
Correct |
69 ms |
39608 KB |
Output is correct |
48 |
Correct |
175 ms |
39652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
39500 KB |
Output is correct |
2 |
Correct |
21 ms |
39392 KB |
Output is correct |
3 |
Correct |
23 ms |
39456 KB |
Output is correct |
4 |
Correct |
22 ms |
39380 KB |
Output is correct |
5 |
Correct |
21 ms |
39444 KB |
Output is correct |
6 |
Correct |
22 ms |
39372 KB |
Output is correct |
7 |
Correct |
25 ms |
39364 KB |
Output is correct |
8 |
Correct |
21 ms |
39456 KB |
Output is correct |
9 |
Correct |
22 ms |
39456 KB |
Output is correct |
10 |
Correct |
21 ms |
39380 KB |
Output is correct |
11 |
Correct |
24 ms |
39408 KB |
Output is correct |
12 |
Correct |
24 ms |
39452 KB |
Output is correct |
13 |
Correct |
22 ms |
39420 KB |
Output is correct |
14 |
Correct |
22 ms |
39444 KB |
Output is correct |
15 |
Correct |
22 ms |
39384 KB |
Output is correct |
16 |
Correct |
21 ms |
39420 KB |
Output is correct |
17 |
Correct |
21 ms |
39432 KB |
Output is correct |
18 |
Correct |
22 ms |
39372 KB |
Output is correct |
19 |
Correct |
22 ms |
39408 KB |
Output is correct |
20 |
Correct |
23 ms |
39452 KB |
Output is correct |
21 |
Correct |
21 ms |
39372 KB |
Output is correct |
22 |
Correct |
25 ms |
39348 KB |
Output is correct |
23 |
Correct |
22 ms |
39396 KB |
Output is correct |
24 |
Correct |
23 ms |
39448 KB |
Output is correct |
25 |
Correct |
24 ms |
39756 KB |
Output is correct |
26 |
Correct |
23 ms |
39756 KB |
Output is correct |
27 |
Correct |
25 ms |
39836 KB |
Output is correct |
28 |
Correct |
25 ms |
39852 KB |
Output is correct |
29 |
Correct |
25 ms |
39852 KB |
Output is correct |
30 |
Correct |
25 ms |
39776 KB |
Output is correct |
31 |
Correct |
25 ms |
39992 KB |
Output is correct |
32 |
Correct |
25 ms |
39752 KB |
Output is correct |
33 |
Correct |
28 ms |
39788 KB |
Output is correct |
34 |
Correct |
28 ms |
39856 KB |
Output is correct |
35 |
Correct |
25 ms |
39788 KB |
Output is correct |
36 |
Correct |
24 ms |
39756 KB |
Output is correct |
37 |
Correct |
25 ms |
39900 KB |
Output is correct |
38 |
Correct |
25 ms |
40012 KB |
Output is correct |
39 |
Correct |
25 ms |
39776 KB |
Output is correct |
40 |
Correct |
25 ms |
39664 KB |
Output is correct |
41 |
Correct |
24 ms |
39632 KB |
Output is correct |
42 |
Correct |
24 ms |
39608 KB |
Output is correct |
43 |
Correct |
28 ms |
39492 KB |
Output is correct |
44 |
Correct |
24 ms |
39540 KB |
Output is correct |
45 |
Correct |
27 ms |
39492 KB |
Output is correct |
46 |
Correct |
31 ms |
39508 KB |
Output is correct |
47 |
Correct |
69 ms |
39608 KB |
Output is correct |
48 |
Correct |
175 ms |
39652 KB |
Output is correct |
49 |
Correct |
819 ms |
77080 KB |
Output is correct |
50 |
Correct |
783 ms |
79720 KB |
Output is correct |
51 |
Correct |
799 ms |
82120 KB |
Output is correct |
52 |
Correct |
796 ms |
73836 KB |
Output is correct |
53 |
Correct |
656 ms |
80836 KB |
Output is correct |
54 |
Correct |
660 ms |
83328 KB |
Output is correct |
55 |
Correct |
665 ms |
76988 KB |
Output is correct |
56 |
Correct |
659 ms |
79828 KB |
Output is correct |
57 |
Correct |
659 ms |
85268 KB |
Output is correct |
58 |
Correct |
667 ms |
82180 KB |
Output is correct |
59 |
Correct |
681 ms |
82116 KB |
Output is correct |
60 |
Correct |
685 ms |
80728 KB |
Output is correct |
61 |
Correct |
990 ms |
105780 KB |
Output is correct |
62 |
Correct |
987 ms |
98676 KB |
Output is correct |
63 |
Correct |
924 ms |
71008 KB |
Output is correct |
64 |
Correct |
971 ms |
63816 KB |
Output is correct |
65 |
Correct |
900 ms |
59460 KB |
Output is correct |
66 |
Correct |
875 ms |
57084 KB |
Output is correct |
67 |
Correct |
852 ms |
55916 KB |
Output is correct |
68 |
Correct |
884 ms |
55464 KB |
Output is correct |
69 |
Correct |
896 ms |
55276 KB |
Output is correct |
70 |
Correct |
933 ms |
55224 KB |
Output is correct |
71 |
Correct |
949 ms |
55064 KB |
Output is correct |
72 |
Correct |
991 ms |
55164 KB |
Output is correct |
73 |
Execution timed out |
2091 ms |
55084 KB |
Time limit exceeded |
74 |
Halted |
0 ms |
0 KB |
- |