# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1109845 | 2024-11-07T19:39:09 Z | SonicML | Dreaming (IOI13_dreaming) | C++14 | 37 ms | 13136 KB |
#include "dreaming.h" #include <vector> #include <iostream> using namespace std; struct Edge{ int to; int cost; }; int const NMAX = 1e5; vector <Edge> g[1 + NMAX]; int below[1 + NMAX]; int above[1 + NMAX]; int visit[1 + NMAX]; void computeBelow(int node, int parent) { visit[node] = true; for(int i = 0;i < g[node].size();i++) { int to = g[node][i].to, cost = g[node][i].cost; if(to != parent) { computeBelow(to, node); below[node] = max(below[node], below[to] + cost); } } } int computeAbove(int node, int parent) { int ans = max(above[node], below[node]); //cerr << node << ' ' << above[node] << ' ' << below[node] << '\n'; visit[node] = true; int best1 = above[node], best2 = 0; for(int i = 0;i < g[node].size();i++) { int to = g[node][i].to, cost = g[node][i].cost; if(to != parent) { if(best1 < below[to] + cost) { best2 = best1; best1 = below[to] + cost; }else if(best2 < below[to] + cost) { best2 = below[to] + cost; } } } for(int i = 0;i < g[node].size();i++) { int to = g[node][i].to, cost = g[node][i].cost; if(to != parent) { if(below[to] + cost == best1) { above[to] = best2 + cost; }else { above[to] = best1 + cost; } ans = min(ans, computeAbove(to, node)); } } return ans; } int travelTime(int N, int M, int L, int A[], int B[], int T[]) { for(int i = 0;i < M;i++) { g[A[i]].push_back({B[i], T[i]}); g[B[i]].push_back({A[i], T[i]}); } for(int i = 0;i < N;i++) { if(!visit[i]) { computeBelow(i, i); } } for(int i = 0;i < N;i++) { visit[i] = 0; } vector <int> len; int core = 0; for(int i = 0;i < N;i++) { if(!visit[i]) { int temp = computeAbove(i, i); //cerr << temp << '\n'; len.push_back(temp); if(len[core] < temp) { core = len.size()-1; } } } //cerr << '\n'; int best1 = 0, best2 = 0; for(int i = 0;i < len.size();i++) { int temp; if(i == core) { temp = len[i]; }else { temp = len[i] + L; } if(best1 < temp) { best2 = best1; best1 = temp; }else if(best2 < temp) { best2 = temp; } } return best1 + best2; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 37 ms | 13136 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 4944 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 37 ms | 13136 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 17 ms | 8016 KB | Output is correct |
2 | Correct | 12 ms | 7760 KB | Output is correct |
3 | Correct | 13 ms | 8016 KB | Output is correct |
4 | Correct | 13 ms | 7760 KB | Output is correct |
5 | Correct | 13 ms | 7720 KB | Output is correct |
6 | Correct | 13 ms | 8164 KB | Output is correct |
7 | Correct | 13 ms | 7892 KB | Output is correct |
8 | Correct | 12 ms | 7752 KB | Output is correct |
9 | Correct | 16 ms | 7760 KB | Output is correct |
10 | Correct | 15 ms | 7884 KB | Output is correct |
11 | Correct | 1 ms | 5112 KB | Output is correct |
12 | Correct | 3 ms | 5580 KB | Output is correct |
13 | Correct | 3 ms | 5580 KB | Output is correct |
14 | Correct | 3 ms | 5616 KB | Output is correct |
15 | Correct | 3 ms | 5580 KB | Output is correct |
16 | Correct | 3 ms | 5580 KB | Output is correct |
17 | Correct | 4 ms | 5580 KB | Output is correct |
18 | Correct | 3 ms | 5580 KB | Output is correct |
19 | Correct | 3 ms | 5580 KB | Output is correct |
20 | Correct | 1 ms | 2896 KB | Output is correct |
21 | Correct | 1 ms | 2896 KB | Output is correct |
22 | Correct | 1 ms | 4944 KB | Output is correct |
23 | Correct | 4 ms | 5580 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 4944 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 37 ms | 13136 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |