# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
61258 | 2018-07-25T14:15:39 Z | Eae02 | Dreaming (IOI13_dreaming) | C++14 | 70 ms | 14328 KB |
#include "dreaming.h" #include <bits/stdc++.h> struct Edge { int len; struct Node* next; }; struct Node { std::vector<Edge> edges; int diamEdge; int component = -1; }; void initComponent(Node* node) { for (const Edge& e : node->edges) { if (e.next->component != -1) continue; e.next->component = node->component; initComponent(e.next); } } std::pair<Node*, int> furthestNode(Node* node, Node* prev) { std::pair<Node*, int> furthest(node, 0); for (int i = 0; i < node->edges.size(); i++) { if (node->edges[i].next == prev) continue; auto c = furthestNode(node->edges[i].next, node); c.second += node->edges[i].len; if (c.second > furthest.second) { node->diamEdge = i; furthest = c; } } return furthest; } int travelTime(int numNodes, int numEdges, int newEdgeLen, int A[], int B[], int T[]) { std::vector<Node> nodes(numNodes); for (int i = 0; i < numEdges; i++) { int n1 = A[i]; int n2 = B[i]; nodes[n1].edges.push_back(Edge { T[i], &nodes[n2] }); nodes[n2].edges.push_back(Edge { T[i], &nodes[n1] }); } struct Comp { Node* mid; int depth; inline bool operator<(const Comp& other) const { return depth > other.depth; } }; std::vector<Comp> componentInfo; int numComponents = 0; int diameter; for (int i = 0; i < numNodes; i++) { if (nodes[i].component != -1) continue; nodes[i].component = numComponents++; initComponent(&nodes[i]); auto f1 = furthestNode(&nodes[i], nullptr); auto f2 = furthestNode(f1.first, nullptr); diameter = f2.second; Node* n = f1.first; int halfDiam = std::round(diameter / 2.0); int d = 0; while (d < halfDiam) { d += n->edges[n->diamEdge].len; n = n->edges[n->diamEdge].next; } componentInfo.push_back(Comp { n, std::max(d, diameter - d) }); } if (numComponents == 1) return diameter; std::sort(componentInfo.begin(), componentInfo.end()); int maxDist = diameter; maxDist = std::max(maxDist, componentInfo[0].depth + componentInfo[1].depth + newEdgeLen); if (numComponents > 2) maxDist = std::max(maxDist, componentInfo[1].depth + componentInfo[2].depth + newEdgeLen * 2); return maxDist; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 70 ms | 14328 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 70 ms | 14328 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 70 ms | 14328 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 30 ms | 6780 KB | Output is correct |
2 | Correct | 40 ms | 6800 KB | Output is correct |
3 | Correct | 28 ms | 6772 KB | Output is correct |
4 | Correct | 30 ms | 6780 KB | Output is correct |
5 | Correct | 29 ms | 6780 KB | Output is correct |
6 | Correct | 32 ms | 8176 KB | Output is correct |
7 | Correct | 32 ms | 7028 KB | Output is correct |
8 | Correct | 29 ms | 6652 KB | Output is correct |
9 | Correct | 27 ms | 6640 KB | Output is correct |
10 | Correct | 30 ms | 7032 KB | Output is correct |
11 | Correct | 2 ms | 384 KB | Output is correct |
12 | Correct | 10 ms | 5748 KB | Output is correct |
13 | Correct | 10 ms | 5620 KB | Output is correct |
14 | Correct | 10 ms | 5748 KB | Output is correct |
15 | Correct | 10 ms | 5748 KB | Output is correct |
16 | Correct | 9 ms | 5652 KB | Output is correct |
17 | Correct | 9 ms | 5620 KB | Output is correct |
18 | Correct | 10 ms | 5748 KB | Output is correct |
19 | Correct | 10 ms | 5748 KB | Output is correct |
20 | Correct | 2 ms | 384 KB | Output is correct |
21 | Correct | 2 ms | 384 KB | Output is correct |
22 | Correct | 2 ms | 512 KB | Output is correct |
23 | Correct | 9 ms | 5620 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 70 ms | 14328 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 70 ms | 14328 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |