| Task: | Tietoverkko |
| Sender: | mbezirgan |
| Submission time: | 2021-10-17 11:23:55 +0300 |
| Language: | C++ (C++17) |
| Status: | READY |
| Result: | 25 |
| group | verdict | score |
|---|---|---|
| #1 | ACCEPTED | 10 |
| #2 | ACCEPTED | 15 |
| #3 | RUNTIME ERROR | 0 |
| test | verdict | time | group | |
|---|---|---|---|---|
| #1 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
| #2 | ACCEPTED | 0.29 s | 2, 3 | details |
| #3 | RUNTIME ERROR | 0.34 s | 3 | details |
Code
#include <iostream>
#include <string>
#include <vector>
#include <memory>
struct Connection;
struct Computer
{
Computer() = default;
Computer(uint32_t n)
{
// 1 is useless as it's its self, but is kept so that searching a connections is easy.
computerConnections = new uint32_t[n];
}
uint32_t* computerConnections;
};
struct Connection
{
Computer* a;
Computer* b;
uint64_t speed;
};
int main()
{
uint64_t n;
std::cin >> n;
Computer* computers = new Computer[n];
bool* checked = new bool[n]();
uint64_t totalSpeed = 0;
// For this to work the fastest way possible the input should be put in order
// Initialize computers
for (uint32_t i = 0; i < n; i++)
{
computers[i] = Computer(n);
}
// First input
{
uint32_t a, b;
std::cin >> a;
std::cin >> b;
uint32_t speed;
std::cin >> speed;
totalSpeed += speed;
Computer* c1 = a - 1 + computers;
Computer* c2 = b - 1 + computers;
c1->computerConnections[b - 1] = speed;
c2->computerConnections[a - 1] = speed;
checked[a - 1] = true;
checked[b - 1] = true;
}
for (uint32_t i = 1; i < n - 1; i++)
{
uint32_t a, b;
std::cin >> a;
std::cin >> b;
uint32_t speed;
std::cin >> speed;
totalSpeed += speed;
Computer* c1 = a - 1 + computers;
Computer* c2 = b - 1 + computers;
c1->computerConnections[b - 1] = speed;
c2->computerConnections[a - 1] = speed;
Computer* cA= checked[c1 - computers] ? c1 : c2;
Computer* cB= checked[c1 - computers] ? c2 : c1;
// Loop through all known computers
for (uint32_t j = 0; j < i + 1; j++)
{
if (&computers[j] == cA)
continue;
uint32_t lowestSpeed = computers[j].computerConnections[cA - computers];
lowestSpeed = lowestSpeed > speed ? speed : lowestSpeed;
computers[j].computerConnections[cB - computers] = lowestSpeed;
cB->computerConnections[j] = lowestSpeed;
totalSpeed += lowestSpeed;
}
checked[cB - computers] = true;
}
std::cout << totalSpeed;
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: RUNTIME ERROR
| input |
|---|
| 200000 1 2 613084013 1 3 832364259 2 4 411999902 3 5 989696303 ... |
| correct output |
|---|
| 1080549209850010931 |
| user output |
|---|
| (empty) |
