# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
93026 | 2019-01-06T10:03:23 Z | davitmarg | Hard route (IZhO17_road) | C++17 | 973 ms | 262136 KB |
/* DEATH-MATCH Davit-Marg */ #include <iostream> #include <algorithm> #include <cmath> #include <vector> #include <string> #include <cstring> #include <map> #include <set> #include <queue> #include <deque> #include <stack> #include <iterator> #include <ctype.h> #include <stdlib.h> #include <cassert> #include <fstream> #define mod 1000000007ll #define LL long long #define LD long double #define MP make_pair #define PB push_back using namespace std; const int N = 5003; int n,used[N][N],st; vector<int> g[N]; pair<LL, LL> dp[N][N]; LL best; int u[N*N]; void dfsinit(int v) { used[st][v] = 1; for (int i = 0; i < g[v].size(); i++) { int to = g[v][i]; if (used[st][to] == 1) continue; dfsinit(to); if (dp[st][to].first + 1 >= dp[st][v].first) { dp[st][v].second = dp[st][v].first; dp[st][v].first = dp[st][to].first + 1; } else if (dp[st][to].first + 1 >= dp[st][v].second) dp[st][v].second = dp[st][to].first + 1; } } void dfs(int v, LL d = 0, LL h = 0) { used[st][v] = 2; if (g[v].size() == 1 && st!=v) { best = max(best, h*d); u[h*d]++; } for (int i = 0; i < g[v].size(); i++) { int to = g[v][i]; if (used[st][to]==2) continue; LL H; if (dp[st][to].first + 1 == dp[st][v].first) H = max(h,dp[st][v].second); else H = max(h, dp[st][v].first); dfs(to,d+1,H); } } int main() { cin >> n; for (int i = 0; i < n-1; i++) { int a, b; //cin >> a >> b; scanf("%d%d",&a,&b); g[a].PB(b); g[b].PB(a); } for (st = 1; st <= n; st++) if(g[st].size()==1) { dfsinit(st); dfs(st); } cout << best << " " << u[best] / 2 << endl; return 0; } /* */
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 504 KB | Output is correct |
2 | Correct | 2 ms | 504 KB | Output is correct |
3 | Correct | 2 ms | 504 KB | Output is correct |
4 | Correct | 2 ms | 504 KB | Output is correct |
5 | Correct | 2 ms | 504 KB | Output is correct |
6 | Correct | 2 ms | 504 KB | Output is correct |
7 | Correct | 2 ms | 760 KB | Output is correct |
8 | Correct | 2 ms | 632 KB | Output is correct |
9 | Correct | 2 ms | 760 KB | Output is correct |
10 | Correct | 2 ms | 760 KB | Output is correct |
11 | Correct | 2 ms | 1016 KB | Output is correct |
12 | Correct | 3 ms | 1016 KB | Output is correct |
13 | Correct | 2 ms | 1016 KB | Output is correct |
14 | Correct | 2 ms | 1020 KB | Output is correct |
15 | Correct | 2 ms | 508 KB | Output is correct |
16 | Correct | 2 ms | 632 KB | Output is correct |
17 | Correct | 2 ms | 504 KB | Output is correct |
18 | Correct | 2 ms | 504 KB | Output is correct |
19 | Correct | 2 ms | 504 KB | Output is correct |
20 | Correct | 2 ms | 504 KB | Output is correct |
21 | Correct | 2 ms | 508 KB | Output is correct |
22 | Correct | 2 ms | 504 KB | Output is correct |
23 | Correct | 2 ms | 632 KB | Output is correct |
24 | Correct | 3 ms | 1400 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 504 KB | Output is correct |
2 | Correct | 2 ms | 504 KB | Output is correct |
3 | Correct | 2 ms | 504 KB | Output is correct |
4 | Correct | 2 ms | 504 KB | Output is correct |
5 | Correct | 2 ms | 504 KB | Output is correct |
6 | Correct | 2 ms | 504 KB | Output is correct |
7 | Correct | 2 ms | 760 KB | Output is correct |
8 | Correct | 2 ms | 632 KB | Output is correct |
9 | Correct | 2 ms | 760 KB | Output is correct |
10 | Correct | 2 ms | 760 KB | Output is correct |
11 | Correct | 2 ms | 1016 KB | Output is correct |
12 | Correct | 3 ms | 1016 KB | Output is correct |
13 | Correct | 2 ms | 1016 KB | Output is correct |
14 | Correct | 2 ms | 1020 KB | Output is correct |
15 | Correct | 2 ms | 508 KB | Output is correct |
16 | Correct | 2 ms | 632 KB | Output is correct |
17 | Correct | 2 ms | 504 KB | Output is correct |
18 | Correct | 2 ms | 504 KB | Output is correct |
19 | Correct | 2 ms | 504 KB | Output is correct |
20 | Correct | 2 ms | 504 KB | Output is correct |
21 | Correct | 2 ms | 508 KB | Output is correct |
22 | Correct | 2 ms | 504 KB | Output is correct |
23 | Correct | 2 ms | 632 KB | Output is correct |
24 | Correct | 3 ms | 1400 KB | Output is correct |
25 | Correct | 475 ms | 130616 KB | Output is correct |
26 | Correct | 464 ms | 129912 KB | Output is correct |
27 | Correct | 445 ms | 130964 KB | Output is correct |
28 | Correct | 450 ms | 130232 KB | Output is correct |
29 | Correct | 973 ms | 261780 KB | Output is correct |
30 | Correct | 973 ms | 261860 KB | Output is correct |
31 | Correct | 916 ms | 262136 KB | Output is correct |
32 | Correct | 869 ms | 261948 KB | Output is correct |
33 | Correct | 8 ms | 2428 KB | Output is correct |
34 | Correct | 7 ms | 2420 KB | Output is correct |
35 | Correct | 8 ms | 2424 KB | Output is correct |
36 | Correct | 8 ms | 2552 KB | Output is correct |
37 | Correct | 5 ms | 1144 KB | Output is correct |
38 | Correct | 5 ms | 1144 KB | Output is correct |
39 | Correct | 6 ms | 1272 KB | Output is correct |
40 | Correct | 9 ms | 1784 KB | Output is correct |
41 | Correct | 15 ms | 2936 KB | Output is correct |
42 | Correct | 31 ms | 6264 KB | Output is correct |
43 | Correct | 55 ms | 11512 KB | Output is correct |
44 | Correct | 98 ms | 21624 KB | Output is correct |
45 | Correct | 223 ms | 49272 KB | Output is correct |
46 | Correct | 307 ms | 87544 KB | Output is correct |
47 | Correct | 752 ms | 240992 KB | Output is correct |
48 | Correct | 745 ms | 138360 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 504 KB | Output is correct |
2 | Correct | 2 ms | 504 KB | Output is correct |
3 | Correct | 2 ms | 504 KB | Output is correct |
4 | Correct | 2 ms | 504 KB | Output is correct |
5 | Correct | 2 ms | 504 KB | Output is correct |
6 | Correct | 2 ms | 504 KB | Output is correct |
7 | Correct | 2 ms | 760 KB | Output is correct |
8 | Correct | 2 ms | 632 KB | Output is correct |
9 | Correct | 2 ms | 760 KB | Output is correct |
10 | Correct | 2 ms | 760 KB | Output is correct |
11 | Correct | 2 ms | 1016 KB | Output is correct |
12 | Correct | 3 ms | 1016 KB | Output is correct |
13 | Correct | 2 ms | 1016 KB | Output is correct |
14 | Correct | 2 ms | 1020 KB | Output is correct |
15 | Correct | 2 ms | 508 KB | Output is correct |
16 | Correct | 2 ms | 632 KB | Output is correct |
17 | Correct | 2 ms | 504 KB | Output is correct |
18 | Correct | 2 ms | 504 KB | Output is correct |
19 | Correct | 2 ms | 504 KB | Output is correct |
20 | Correct | 2 ms | 504 KB | Output is correct |
21 | Correct | 2 ms | 508 KB | Output is correct |
22 | Correct | 2 ms | 504 KB | Output is correct |
23 | Correct | 2 ms | 632 KB | Output is correct |
24 | Correct | 3 ms | 1400 KB | Output is correct |
25 | Correct | 475 ms | 130616 KB | Output is correct |
26 | Correct | 464 ms | 129912 KB | Output is correct |
27 | Correct | 445 ms | 130964 KB | Output is correct |
28 | Correct | 450 ms | 130232 KB | Output is correct |
29 | Correct | 973 ms | 261780 KB | Output is correct |
30 | Correct | 973 ms | 261860 KB | Output is correct |
31 | Correct | 916 ms | 262136 KB | Output is correct |
32 | Correct | 869 ms | 261948 KB | Output is correct |
33 | Correct | 8 ms | 2428 KB | Output is correct |
34 | Correct | 7 ms | 2420 KB | Output is correct |
35 | Correct | 8 ms | 2424 KB | Output is correct |
36 | Correct | 8 ms | 2552 KB | Output is correct |
37 | Correct | 5 ms | 1144 KB | Output is correct |
38 | Correct | 5 ms | 1144 KB | Output is correct |
39 | Correct | 6 ms | 1272 KB | Output is correct |
40 | Correct | 9 ms | 1784 KB | Output is correct |
41 | Correct | 15 ms | 2936 KB | Output is correct |
42 | Correct | 31 ms | 6264 KB | Output is correct |
43 | Correct | 55 ms | 11512 KB | Output is correct |
44 | Correct | 98 ms | 21624 KB | Output is correct |
45 | Correct | 223 ms | 49272 KB | Output is correct |
46 | Correct | 307 ms | 87544 KB | Output is correct |
47 | Correct | 752 ms | 240992 KB | Output is correct |
48 | Correct | 745 ms | 138360 KB | Output is correct |
49 | Runtime error | 314 ms | 50228 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
50 | Halted | 0 ms | 0 KB | - |