# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
35063 | 2017-11-17T20:53:38 Z | model_code | Hard route (IZhO17_road) | C++11 | 2000 ms | 68648 KB |
#include <iostream> #include <cstdio> #include <cstring> #include <string> #include <vector> #include <cmath> #include <algorithm> #include <set> #include <map> #include <queue> #include <ctime> #define pb push_back #define ll long long #define mp make_pair #define f first #define s second #define pii pair < int, int > #define ull unsigned long long #define pll pair < ll, ll > #define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it ++) #define all(s) s.begin(), s.end() #define sz(a) (int)a.size() const int inf = (1ll << 30) - 1; const int maxn = (int) 1e5 + 10; using namespace std; vector<int> g[1000100]; int d[1000100]; int d2[1000100]; int n; int dis, cnt; int X; void dfs(int v, int p = -1){ d[v] = 0; d2[v] = 0; for(int i = 0; i < g[v].size(); i++){ int to = g[v][i]; if(to == p ) continue; dfs(to, v); if(d[v] < d[to] + 1){ d2[v] = d[v]; d[v] = d[to] + 1; } else if(d2[v] < d[to] + 1){ d2[v] = d[to] + 1; } } } void get(int v, int p = -1, int mx = 0, int lev = 0){ int ccnt = 0; for(int i = 0; i < g[v].size(); i++){ int to = g[v][i]; if(to == p) continue; ccnt++; int mx2 = mx; if(d[v] == d[to] + 1) mx2 = max(mx2, d2[v]); else mx2 = max(d[v], mx2); get(to, v, mx2, lev + 1); } if(ccnt > 0) return; if(X >= v) return; int cur = lev * mx; if(dis < cur){ dis = cur; cnt = 0; } if(cur == dis) cnt++; } void calc(int x){ X = x; dfs(X); get(X); } void solve(){ scanf("%d", &n); for(int i = 1, x, y; i < n; i++){ scanf("%d%d", &x, &y); g[x].pb(y); g[y].pb(x); } if(n == 2){ printf("0 1\n"); return; } pii ans = mp(0, 0); for(int i = 1; i <= n; i++){ if(g[i].size()==1){ calc(i); } } printf("%d %d\n", dis, cnt); } int main () { int t=1; //scanf("%d", &t); for(int i=1; i <= t; i++){ //printf("Case #%d\n", i); solve(); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 33268 KB | Output is correct |
2 | Correct | 6 ms | 33268 KB | Output is correct |
3 | Correct | 3 ms | 33268 KB | Output is correct |
4 | Correct | 3 ms | 33268 KB | Output is correct |
5 | Correct | 3 ms | 33268 KB | Output is correct |
6 | Correct | 13 ms | 33268 KB | Output is correct |
7 | Correct | 6 ms | 33268 KB | Output is correct |
8 | Correct | 6 ms | 33268 KB | Output is correct |
9 | Correct | 3 ms | 33268 KB | Output is correct |
10 | Correct | 6 ms | 33268 KB | Output is correct |
11 | Correct | 3 ms | 33268 KB | Output is correct |
12 | Correct | 3 ms | 33268 KB | Output is correct |
13 | Correct | 3 ms | 33268 KB | Output is correct |
14 | Correct | 6 ms | 33268 KB | Output is correct |
15 | Correct | 3 ms | 33268 KB | Output is correct |
16 | Correct | 6 ms | 33268 KB | Output is correct |
17 | Correct | 3 ms | 33268 KB | Output is correct |
18 | Correct | 9 ms | 33268 KB | Output is correct |
19 | Correct | 13 ms | 33268 KB | Output is correct |
20 | Correct | 9 ms | 33268 KB | Output is correct |
21 | Correct | 9 ms | 33268 KB | Output is correct |
22 | Correct | 6 ms | 33268 KB | Output is correct |
23 | Correct | 3 ms | 33268 KB | Output is correct |
24 | Correct | 9 ms | 33268 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 33268 KB | Output is correct |
2 | Correct | 6 ms | 33268 KB | Output is correct |
3 | Correct | 3 ms | 33268 KB | Output is correct |
4 | Correct | 3 ms | 33268 KB | Output is correct |
5 | Correct | 3 ms | 33268 KB | Output is correct |
6 | Correct | 13 ms | 33268 KB | Output is correct |
7 | Correct | 6 ms | 33268 KB | Output is correct |
8 | Correct | 6 ms | 33268 KB | Output is correct |
9 | Correct | 3 ms | 33268 KB | Output is correct |
10 | Correct | 6 ms | 33268 KB | Output is correct |
11 | Correct | 3 ms | 33268 KB | Output is correct |
12 | Correct | 3 ms | 33268 KB | Output is correct |
13 | Correct | 3 ms | 33268 KB | Output is correct |
14 | Correct | 6 ms | 33268 KB | Output is correct |
15 | Correct | 3 ms | 33268 KB | Output is correct |
16 | Correct | 6 ms | 33268 KB | Output is correct |
17 | Correct | 3 ms | 33268 KB | Output is correct |
18 | Correct | 9 ms | 33268 KB | Output is correct |
19 | Correct | 13 ms | 33268 KB | Output is correct |
20 | Correct | 9 ms | 33268 KB | Output is correct |
21 | Correct | 9 ms | 33268 KB | Output is correct |
22 | Correct | 6 ms | 33268 KB | Output is correct |
23 | Correct | 3 ms | 33268 KB | Output is correct |
24 | Correct | 9 ms | 33268 KB | Output is correct |
25 | Correct | 389 ms | 33476 KB | Output is correct |
26 | Correct | 393 ms | 33468 KB | Output is correct |
27 | Correct | 396 ms | 33472 KB | Output is correct |
28 | Correct | 399 ms | 33468 KB | Output is correct |
29 | Correct | 506 ms | 33472 KB | Output is correct |
30 | Correct | 539 ms | 33472 KB | Output is correct |
31 | Correct | 499 ms | 33472 KB | Output is correct |
32 | Correct | 496 ms | 33472 KB | Output is correct |
33 | Correct | 16 ms | 33572 KB | Output is correct |
34 | Correct | 9 ms | 33568 KB | Output is correct |
35 | Correct | 13 ms | 33568 KB | Output is correct |
36 | Correct | 13 ms | 33564 KB | Output is correct |
37 | Correct | 9 ms | 33668 KB | Output is correct |
38 | Correct | 16 ms | 33664 KB | Output is correct |
39 | Correct | 9 ms | 33432 KB | Output is correct |
40 | Correct | 13 ms | 33400 KB | Output is correct |
41 | Correct | 19 ms | 33400 KB | Output is correct |
42 | Correct | 29 ms | 33400 KB | Output is correct |
43 | Correct | 49 ms | 33400 KB | Output is correct |
44 | Correct | 93 ms | 33400 KB | Output is correct |
45 | Correct | 163 ms | 33400 KB | Output is correct |
46 | Correct | 206 ms | 33400 KB | Output is correct |
47 | Correct | 519 ms | 33400 KB | Output is correct |
48 | Correct | 806 ms | 33532 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 33268 KB | Output is correct |
2 | Correct | 6 ms | 33268 KB | Output is correct |
3 | Correct | 3 ms | 33268 KB | Output is correct |
4 | Correct | 3 ms | 33268 KB | Output is correct |
5 | Correct | 3 ms | 33268 KB | Output is correct |
6 | Correct | 13 ms | 33268 KB | Output is correct |
7 | Correct | 6 ms | 33268 KB | Output is correct |
8 | Correct | 6 ms | 33268 KB | Output is correct |
9 | Correct | 3 ms | 33268 KB | Output is correct |
10 | Correct | 6 ms | 33268 KB | Output is correct |
11 | Correct | 3 ms | 33268 KB | Output is correct |
12 | Correct | 3 ms | 33268 KB | Output is correct |
13 | Correct | 3 ms | 33268 KB | Output is correct |
14 | Correct | 6 ms | 33268 KB | Output is correct |
15 | Correct | 3 ms | 33268 KB | Output is correct |
16 | Correct | 6 ms | 33268 KB | Output is correct |
17 | Correct | 3 ms | 33268 KB | Output is correct |
18 | Correct | 9 ms | 33268 KB | Output is correct |
19 | Correct | 13 ms | 33268 KB | Output is correct |
20 | Correct | 9 ms | 33268 KB | Output is correct |
21 | Correct | 9 ms | 33268 KB | Output is correct |
22 | Correct | 6 ms | 33268 KB | Output is correct |
23 | Correct | 3 ms | 33268 KB | Output is correct |
24 | Correct | 9 ms | 33268 KB | Output is correct |
25 | Correct | 389 ms | 33476 KB | Output is correct |
26 | Correct | 393 ms | 33468 KB | Output is correct |
27 | Correct | 396 ms | 33472 KB | Output is correct |
28 | Correct | 399 ms | 33468 KB | Output is correct |
29 | Correct | 506 ms | 33472 KB | Output is correct |
30 | Correct | 539 ms | 33472 KB | Output is correct |
31 | Correct | 499 ms | 33472 KB | Output is correct |
32 | Correct | 496 ms | 33472 KB | Output is correct |
33 | Correct | 16 ms | 33572 KB | Output is correct |
34 | Correct | 9 ms | 33568 KB | Output is correct |
35 | Correct | 13 ms | 33568 KB | Output is correct |
36 | Correct | 13 ms | 33564 KB | Output is correct |
37 | Correct | 9 ms | 33668 KB | Output is correct |
38 | Correct | 16 ms | 33664 KB | Output is correct |
39 | Correct | 9 ms | 33432 KB | Output is correct |
40 | Correct | 13 ms | 33400 KB | Output is correct |
41 | Correct | 19 ms | 33400 KB | Output is correct |
42 | Correct | 29 ms | 33400 KB | Output is correct |
43 | Correct | 49 ms | 33400 KB | Output is correct |
44 | Correct | 93 ms | 33400 KB | Output is correct |
45 | Correct | 163 ms | 33400 KB | Output is correct |
46 | Correct | 206 ms | 33400 KB | Output is correct |
47 | Correct | 519 ms | 33400 KB | Output is correct |
48 | Correct | 806 ms | 33532 KB | Output is correct |
49 | Execution timed out | 2000 ms | 68648 KB | Execution timed out |
50 | Halted | 0 ms | 0 KB | - |