Submission #960803

# Submission time Handle Problem Language Result Execution time Memory
960803 2024-04-11T04:30:33 Z Trisanu_Das Hard route (IZhO17_road) C++17
52 / 100
284 ms 1116 KB
#include <bits/stdc++.h>
using namespace std;
 
const int NM = 5000;
 
int N, deg[NM+5], f[NM+5], g[NM+5], dep[NM+5];
vector <int> adj[NM+5];
int ans = -1, cnt = -1;
 
void dfs(int u, int p){
	dep[u] = (p == -1 ? 0 : dep[p]+1);
	f[u] = g[u] = 0;
	for (int v : adj[u]){
		if (v == p) continue;
		dfs(v, u);
		if (f[v]+1 > f[u]){
			g[u] = f[u];
			f[u] = f[v]+1;
		}
		else if (f[v]+1 > g[u]) g[u] = f[v]+1;
	}
}
 
void calc(int u, int p, int cur){
	bool has_child = 0;
	for (int v : adj[u]){
		if (v == p) continue;
		has_child = 1;
		if (f[v]+1 == f[u]) calc(v, u, max(cur, g[u]));
		else calc(v, u, max(cur, f[u]));
	}
	if (!has_child){
		if (dep[u]*cur > ans){
			ans = dep[u]*cur;
			cnt = 1;
		}
		else if (dep[u]*cur == ans) cnt++;
	}
}
 
void solve(int r){
	dfs(r, -1);
	calc(r, -1, 0);
}
 
int main(){
	ios_base::sync_with_stdio(false); cin.tie(nullptr);
	cin >> N;
	for (int i = 1; i < N; i++){
		int u, v; cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
		deg[u]++; deg[v]++;
	}
	for (int i = 1; i <= N; i++) if (deg[i] == 1) solve(i);
	cout << ans << ' ' << cnt / 2;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 580 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 580 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 600 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 580 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 580 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 600 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 150 ms 1036 KB Output is correct
26 Correct 141 ms 1040 KB Output is correct
27 Correct 143 ms 1108 KB Output is correct
28 Correct 147 ms 860 KB Output is correct
29 Correct 200 ms 1028 KB Output is correct
30 Correct 206 ms 1036 KB Output is correct
31 Correct 203 ms 1028 KB Output is correct
32 Correct 216 ms 856 KB Output is correct
33 Correct 3 ms 1112 KB Output is correct
34 Correct 3 ms 1112 KB Output is correct
35 Correct 3 ms 1112 KB Output is correct
36 Correct 3 ms 1112 KB Output is correct
37 Correct 2 ms 1116 KB Output is correct
38 Correct 2 ms 1116 KB Output is correct
39 Correct 3 ms 1012 KB Output is correct
40 Correct 3 ms 856 KB Output is correct
41 Correct 5 ms 856 KB Output is correct
42 Correct 11 ms 848 KB Output is correct
43 Correct 19 ms 872 KB Output is correct
44 Correct 36 ms 604 KB Output is correct
45 Correct 80 ms 600 KB Output is correct
46 Correct 87 ms 808 KB Output is correct
47 Correct 196 ms 860 KB Output is correct
48 Correct 284 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 580 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 580 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 600 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 150 ms 1036 KB Output is correct
26 Correct 141 ms 1040 KB Output is correct
27 Correct 143 ms 1108 KB Output is correct
28 Correct 147 ms 860 KB Output is correct
29 Correct 200 ms 1028 KB Output is correct
30 Correct 206 ms 1036 KB Output is correct
31 Correct 203 ms 1028 KB Output is correct
32 Correct 216 ms 856 KB Output is correct
33 Correct 3 ms 1112 KB Output is correct
34 Correct 3 ms 1112 KB Output is correct
35 Correct 3 ms 1112 KB Output is correct
36 Correct 3 ms 1112 KB Output is correct
37 Correct 2 ms 1116 KB Output is correct
38 Correct 2 ms 1116 KB Output is correct
39 Correct 3 ms 1012 KB Output is correct
40 Correct 3 ms 856 KB Output is correct
41 Correct 5 ms 856 KB Output is correct
42 Correct 11 ms 848 KB Output is correct
43 Correct 19 ms 872 KB Output is correct
44 Correct 36 ms 604 KB Output is correct
45 Correct 80 ms 600 KB Output is correct
46 Correct 87 ms 808 KB Output is correct
47 Correct 196 ms 860 KB Output is correct
48 Correct 284 ms 1108 KB Output is correct
49 Runtime error 1 ms 604 KB Execution killed with signal 11
50 Halted 0 ms 0 KB -