Task: | Tietoverkko |
Sender: | mbezirgan |
Submission time: | 2021-10-17 00:34:48 +0300 |
Language: | C++ (C++17) |
Status: | READY |
Result: | 25 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 10 |
#2 | ACCEPTED | 15 |
#3 | TIME LIMIT EXCEEDED | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
#2 | ACCEPTED | 0.95 s | 2, 3 | details |
#3 | TIME LIMIT EXCEEDED | -- | 3 | details |
Code
#include <iostream> #include <string> #include <vector> struct Connection; struct Computer { std::vector<Connection*> connections; }; struct Connection { uint64_t a; uint64_t b; uint64_t speed; }; uint64_t SumFactorial(uint64_t n) { uint64_t a = 0; for (uint64_t i = 1; i < n; i++) a += i; return a; } void FindAllPaths(uint64_t lowestSpeed, const Computer* computer, const Computer* distr, const Computer* computers, const Connection* connection, uint64_t* speed, bool* checked) { if (checked[computer - computers]) { if (distr->connections.size() == 1) { return; } } for (auto& c : distr->connections) { if (c != connection) { uint64_t loopLowestSpeed = lowestSpeed; if (loopLowestSpeed > c->speed) loopLowestSpeed = c->speed; if (&computers[c->a] != distr) { FindAllPaths(loopLowestSpeed, computer, &computers[c->a], computers, c, speed, checked); if (!checked[c->a]) { *speed += loopLowestSpeed; } } else { FindAllPaths(loopLowestSpeed, computer, &computers[c->b], computers, c, speed, checked); if (!checked[c->b]) { *speed += loopLowestSpeed; } } } } if (computer == distr) { checked[computer - computers] = true; } } // Generates all paths lengths (can be easily made to also save for what computers they are) void FindConnetionsSpeed(uint64_t n, const Computer* computers, uint64_t* speed) { bool* checked = new bool[n](); for (uint64_t i = 0; i < n - 1; i++) { FindAllPaths(UINT32_MAX, &computers[i], &computers[i], computers, nullptr, speed, checked); } delete[] checked; } int main() { uint64_t n; std::cin >> n; Computer* computers = new Computer[n](); Connection* connections = new Connection[n - 1]; for (uint64_t i = 0; i < n - 1; i++) { auto& c = connections[i]; uint64_t a, b; std::cin >> a; std::cin >> b; c.a = a - 1; c.b = b - 1; computers[c.a].connections.push_back(&c); computers[c.b].connections.push_back(&c); std::cin >> c.speed; } uint64_t speed = 0; FindConnetionsSpeed(n, computers, &speed); std::cout << speed; delete[] connections; delete[] computers; }
Test details
Test 1
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
100 1 2 74 1 3 100 2 4 50 3 5 40 ... |
correct output |
---|
88687 |
user output |
---|
88687 |
Test 2
Group: 2, 3
Verdict: ACCEPTED
input |
---|
5000 1 2 613084013 1 3 832364259 2 4 411999902 3 5 989696303 ... |
correct output |
---|
1103702320243776 |
user output |
---|
1103702320243776 |
Test 3
Group: 3
Verdict: TIME LIMIT EXCEEDED
input |
---|
200000 1 2 613084013 1 3 832364259 2 4 411999902 3 5 989696303 ... |
correct output |
---|
1080549209850010931 |
user output |
---|
(empty) |