| Task: | Sadonkorjuu |
| Sender: | Ihminen |
| Submission time: | 2022-11-13 18:56:40 +0200 |
| Language: | C++ (C++17) |
| Status: | READY |
| Result: | 0 |
| group | verdict | score |
|---|---|---|
| #1 | WRONG ANSWER | 0 |
| #2 | WRONG ANSWER | 0 |
| test | verdict | time | group | |
|---|---|---|---|---|
| #1 | ACCEPTED | 0.00 s | 1, 2 | details |
| #2 | ACCEPTED | 0.00 s | 1, 2 | details |
| #3 | ACCEPTED | 0.00 s | 1, 2 | details |
| #4 | ACCEPTED | 0.00 s | 1, 2 | details |
| #5 | ACCEPTED | 0.00 s | 1, 2 | details |
| #6 | WRONG ANSWER | 0.01 s | 1, 2 | details |
| #7 | RUNTIME ERROR | 0.36 s | 2 | details |
| #8 | ACCEPTED | 0.10 s | 1, 2 | details |
| #9 | RUNTIME ERROR | 0.36 s | 2 | details |
| #10 | ACCEPTED | 0.18 s | 1, 2 | details |
| #11 | RUNTIME ERROR | 0.36 s | 2 | details |
| #12 | RUNTIME ERROR | 0.36 s | 2 | details |
| #13 | RUNTIME ERROR | 0.37 s | 2 | details |
| #14 | RUNTIME ERROR | 0.36 s | 2 | details |
| #15 | WRONG ANSWER | 0.01 s | 1, 2 | details |
| #16 | ACCEPTED | 0.06 s | 1, 2 | details |
| #17 | ACCEPTED | 0.10 s | 1, 2 | details |
| #18 | ACCEPTED | 0.02 s | 1, 2 | details |
| #19 | ACCEPTED | 0.16 s | 1, 2 | details |
| #20 | ACCEPTED | 0.09 s | 1, 2 | details |
| #21 | RUNTIME ERROR | 0.36 s | 2 | details |
| #22 | RUNTIME ERROR | 0.36 s | 2 | details |
| #23 | RUNTIME ERROR | 0.36 s | 2 | details |
| #24 | ACCEPTED | 0.09 s | 1, 2 | details |
| #25 | RUNTIME ERROR | 0.36 s | 2 | details |
| #26 | ACCEPTED | 0.07 s | 1, 2 | details |
| #27 | RUNTIME ERROR | 0.34 s | 2 | details |
| #28 | ACCEPTED | 0.01 s | 1, 2 | details |
| #29 | RUNTIME ERROR | 0.34 s | 2 | details |
| #30 | ACCEPTED | 0.01 s | 1, 2 | details |
| #31 | RUNTIME ERROR | 0.36 s | 2 | details |
Compiler report
input/code.cpp: In function 'int main()':
input/code.cpp:364:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
364 | for (int i = 0; i < satamat.size(); i++) {
| ~~^~~~~~~~~~~~~~~~Code
// Sadonkorjuu2.cpp : Defines the entry point for the application.
//
using namespace std;
#include <bits/stdc++.h>
vector<int> satamat;
int pieninMatka[200000] = { };
vector<int> split(const string& str, char delimiter) {
vector<int> tokens;
string token;
istringstream tokenStream(str);
while (getline(tokenStream, token, delimiter)) {
tokens.push_back(stoi(token));
}
return tokens;
}
struct AdjListNode
{
int dest;
int weight;
struct AdjListNode* next;
};
struct AdjList
{
struct AdjListNode* head;
};
struct Graph
{
int V;
struct AdjList* array;
};
struct AdjListNode* newAdjListNode(
int dest, int weight)
{
struct AdjListNode* newNode =
(struct AdjListNode*)
malloc(sizeof(struct AdjListNode));
newNode->dest = dest;
newNode->weight = weight;
newNode->next = NULL;
return newNode;
}
struct Graph* createGraph(int V)
{
struct Graph* graph = (struct Graph*)
malloc(sizeof(struct Graph));
graph->V = V;
graph->array = (struct AdjList*)
malloc(V * sizeof(struct AdjList));
for (int i = 0; i < V; ++i)
graph->array[i].head = NULL;
return graph;
}
void lisääTie(struct Graph* graph, int src,
int dest, int weight)
{
struct AdjListNode* newNode =
newAdjListNode(dest, weight);
newNode->next = graph->array[src].head;
graph->array[src].head = newNode;
newNode = newAdjListNode(src, weight);
newNode->next = graph->array[dest].head;
graph->array[dest].head = newNode;
}
struct MinHeapNode
{
int v;
int dist;
};
struct MinHeap
{
int size;
int capacity;
int* pos;
struct MinHeapNode** array;
};
struct MinHeapNode* newMinHeapNode(int v,
int dist)
{
struct MinHeapNode* minHeapNode =
(struct MinHeapNode*)
malloc(sizeof(struct MinHeapNode));
minHeapNode->v = v;
minHeapNode->dist = dist;
return minHeapNode;
}
struct MinHeap* createMinHeap(int capacity)
{
struct MinHeap* minHeap =
(struct MinHeap*)
malloc(sizeof(struct MinHeap));
minHeap->pos = (int*)malloc(
capacity * sizeof(int));
minHeap->size = 0;
minHeap->capacity = capacity;
minHeap->array =
(struct MinHeapNode**)
malloc(capacity *
sizeof(struct MinHeapNode*));
return minHeap;
}
void swapMinHeapNode(struct MinHeapNode** a,
struct MinHeapNode** b)
{
struct MinHeapNode* t = *a;
*a = *b;
*b = t;
}
void minHeapify(struct MinHeap* minHeap,
int idx)
{
int smallest, left, right;
smallest = idx;
left = 2 * idx + 1;
right = 2 * idx + 2;
if (left < minHeap->size &&
minHeap->array[left]->dist <
minHeap->array[smallest]->dist)
smallest = left;
if (right < minHeap->size &&
minHeap->array[right]->dist <
minHeap->array[smallest]->dist)
smallest = right;
if (smallest != idx)
{
MinHeapNode* smallestNode =
minHeap->array[smallest];
MinHeapNode* idxNode =
minHeap->array[idx];
minHeap->pos[smallestNode->v] = idx;
minHeap->pos[idxNode->v] = smallest;
swapMinHeapNode(&minHeap->array[smallest],
&minHeap->array[idx]);
minHeapify(minHeap, smallest);
}
}
int isEmpty(struct MinHeap* minHeap)
{
return minHeap->size == 0;
}
struct MinHeapNode* extractMin(struct MinHeap*
minHeap)
{
if (isEmpty(minHeap))
return NULL;
struct MinHeapNode* root =
minHeap->array[0];
struct MinHeapNode* lastNode =
minHeap->array[minHeap->size - 1];
minHeap->array[0] = lastNode;
minHeap->pos[root->v] = minHeap->size - 1;
minHeap->pos[lastNode->v] = 0;
--minHeap->size;
minHeapify(minHeap, 0);
return root;
}
void decreaseKey(struct MinHeap* minHeap,
int v, int dist)
{
int i = minHeap->pos[v];
minHeap->array[i]->dist = dist;
while (i && minHeap->array[i]->dist <
minHeap->array[(i - 1) / 2]->dist)
{
minHeap->pos[minHeap->array[i]->v] =
(i - 1) / 2;
minHeap->pos[minHeap->array[
(i - 1) / 2]->v] = i;
swapMinHeapNode(&minHeap->array[i],
&minHeap->array[(i - 1) / 2]);
i = (i - 1) / 2;
}
}
bool isInMinHeap(struct MinHeap* minHeap, int v)
{
if (minHeap->pos[v] < minHeap->size)
return true;
return false;
}
void printArr(int dist[], int n)
{
printf("Vertex Distance from Source\n");
for (int i = 0; i < n; ++i)
printf("%d \t\t %d\n", i, dist[i]);
}
void Laske(struct Graph* graph, int src, int pylväs)
{
int V = graph->V;
int dist[2000] = { };
struct MinHeap* minHeap = createMinHeap(V);
for (int v = 0; v < V; ++v)
{
dist[v] = INT_MAX;
minHeap->array[v] = newMinHeapNode(v,
dist[v]);
minHeap->pos[v] = v;
}
minHeap->array[src] =
newMinHeapNode(src, dist[src]);
minHeap->pos[src] = src;
dist[src] = 0;
decreaseKey(minHeap, src, dist[src]);
minHeap->size = V;
while (!isEmpty(minHeap))
{
struct MinHeapNode* minHeapNode =
extractMin(minHeap);
int u = minHeapNode->v;
struct AdjListNode* pCrawl =
graph->array[u].head;
while (pCrawl != NULL)
{
int v = pCrawl->dest;
if (isInMinHeap(minHeap, v) &&
dist[u] != INT_MAX &&
pCrawl->weight + dist[u] < dist[v])
{
dist[v] = dist[u] + pCrawl->weight;
if (dist[v] < pieninMatka[v]) {
pieninMatka[v] = dist[v];
}
decreaseKey(minHeap, v, dist[v]);
}
pCrawl = pCrawl->next;
}
}
}
int main()
{
fill(pieninMatka, pieninMatka + 200000, 9999);
int V;
cin >> V;
string inputString;
cin.ignore();
getline(cin, inputString);
stringstream stream(inputString);
std::vector<int> valisatamat;
int n;
while (stream >> n) {
valisatamat.push_back(n);
}
for (long unsigned int z = 0; z < valisatamat.size(); z++) {
if (valisatamat[z] == 0) {
satamat.push_back(z);
}
}
int rivimaara = V;
struct Graph* graph = createGraph(V);
for (int i = 0; i < rivimaara - 1; i++) {
string line;
getline(cin, line);
vector<int> rivi = split(line, ' ');
istringstream iss(line);
int num;
iss >> num;
rivi.push_back(num);
lisääTie(graph, rivi[0] - 1, rivi[1] - 1, rivi[2]);
}
for (long unsigned int g = 0; g < satamat.size(); g++) {
Laske(graph, satamat[g], g);
}
int laskin = 0;
for (int j = 0; j < V; j++) {
bool ei = false;
for (int i = 0; i < satamat.size(); i++) {
if (j == satamat[i]) {
ei = true;
break;
}
}
if (ei == false) {
laskin += pieninMatka[j];
}
else
{
laskin += 0;
}
}
cout << laskin;
return 0;
}
Test details
Test 1
Group: 1, 2
Verdict: ACCEPTED
| input |
|---|
| 1 0 |
| correct output |
|---|
| 0 |
| user output |
|---|
| 0 |
Test 2
Group: 1, 2
Verdict: ACCEPTED
| input |
|---|
| 5 0 0 0 0 0 1 2 1 2 3 2 3 4 3 ... |
| correct output |
|---|
| 0 |
| user output |
|---|
| 0 |
Test 3
Group: 1, 2
Verdict: ACCEPTED
| input |
|---|
| 4 1 0 1 1 1 2 10 2 3 20 2 4 30 |
| correct output |
|---|
| 60 |
| user output |
|---|
| 60 |
Test 4
Group: 1, 2
Verdict: ACCEPTED
| input |
|---|
| 5 0 1 1 1 0 1 2 10 2 3 20 3 4 30 ... |
| correct output |
|---|
| 80 |
| user output |
|---|
| 80 |
Test 5
Group: 1, 2
Verdict: ACCEPTED
| input |
|---|
| 5 0 1 0 1 1 1 2 1 2 3 5 3 4 3 ... |
| correct output |
|---|
| 6 |
| user output |
|---|
| 6 |
Test 6
Group: 1, 2
Verdict: WRONG ANSWER
| input |
|---|
| 1000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
| correct output |
|---|
| 5506363 |
| user output |
|---|
| 5506183 |
Test 7
Group: 2
Verdict: RUNTIME ERROR
| input |
|---|
| 200000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
| correct output |
|---|
| 1795118520 |
| user output |
|---|
| (empty) |
Test 8
Group: 1, 2
Verdict: ACCEPTED
| input |
|---|
| 1000 0 0 1 0 1 1 0 1 0 1 1 0 0 0 1 ... |
| correct output |
|---|
| 293576 |
| user output |
|---|
| 293576 |
Test 9
Group: 2
Verdict: RUNTIME ERROR
| input |
|---|
| 200000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
| correct output |
|---|
| 816932444 |
| user output |
|---|
| (empty) |
Test 10
Group: 1, 2
Verdict: ACCEPTED
| input |
|---|
| 1000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... |
| correct output |
|---|
| 3089 |
| user output |
|---|
| 3089 |
Test 11
Group: 2
Verdict: RUNTIME ERROR
| input |
|---|
| 200000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... |
| correct output |
|---|
| 40839 |
| user output |
|---|
| (empty) |
Test 12
Group: 2
Verdict: RUNTIME ERROR
| input |
|---|
| 200000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
| correct output |
|---|
| 5683983203973 |
| user output |
|---|
| (empty) |
Test 13
Group: 2
Verdict: RUNTIME ERROR
| input |
|---|
| 200000 0 1 1 1 1 1 1 0 0 0 1 1 0 1 0 ... |
| correct output |
|---|
| 58572993 |
| user output |
|---|
| (empty) |
Test 14
Group: 2
Verdict: RUNTIME ERROR
| input |
|---|
| 200000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... |
| correct output |
|---|
| 32755 |
| user output |
|---|
| (empty) |
Test 15
Group: 1, 2
Verdict: WRONG ANSWER
| input |
|---|
| 1000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
| correct output |
|---|
| 126238345 |
| user output |
|---|
| 9788123 |
Test 16
Group: 1, 2
Verdict: ACCEPTED
| input |
|---|
| 1000 0 0 0 1 0 1 1 1 0 0 1 0 1 1 0 ... |
| correct output |
|---|
| 278678 |
| user output |
|---|
| 278678 |
Test 17
Group: 1, 2
Verdict: ACCEPTED
| input |
|---|
| 1000 1 0 0 0 1 0 0 0 1 0 0 0 0 0 0 ... |
| correct output |
|---|
| 34929 |
| user output |
|---|
| 34929 |
Test 18
Group: 1, 2
Verdict: ACCEPTED
| input |
|---|
| 1000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
| correct output |
|---|
| 1543963 |
| user output |
|---|
| 1543963 |
Test 19
Group: 1, 2
Verdict: ACCEPTED
| input |
|---|
| 1000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... |
| correct output |
|---|
| 39606 |
| user output |
|---|
| 39606 |
Test 20
Group: 1, 2
Verdict: ACCEPTED
| input |
|---|
| 1000 1 0 1 0 1 0 0 0 0 1 1 0 0 0 1 ... |
| correct output |
|---|
| 321598 |
| user output |
|---|
| 321598 |
Test 21
Group: 2
Verdict: RUNTIME ERROR
| input |
|---|
| 200000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
| correct output |
|---|
| 978670626 |
| user output |
|---|
| (empty) |
Test 22
Group: 2
Verdict: RUNTIME ERROR
| input |
|---|
| 200000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... |
| correct output |
|---|
| 375218 |
| user output |
|---|
| (empty) |
Test 23
Group: 2
Verdict: RUNTIME ERROR
| input |
|---|
| 200000 1 1 1 1 0 0 0 0 0 1 0 1 0 1 1 ... |
| correct output |
|---|
| 60422556 |
| user output |
|---|
| (empty) |
Test 24
Group: 1, 2
Verdict: ACCEPTED
| input |
|---|
| 1000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
| correct output |
|---|
| 291990 |
| user output |
|---|
| 291990 |
Test 25
Group: 2
Verdict: RUNTIME ERROR
| input |
|---|
| 200000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
| correct output |
|---|
| 59607954 |
| user output |
|---|
| (empty) |
Test 26
Group: 1, 2
Verdict: ACCEPTED
| input |
|---|
| 1000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
| correct output |
|---|
| 990 |
| user output |
|---|
| 990 |
Test 27
Group: 2
Verdict: RUNTIME ERROR
| input |
|---|
| 200000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
| correct output |
|---|
| 199982 |
| user output |
|---|
| (empty) |
Test 28
Group: 1, 2
Verdict: ACCEPTED
| input |
|---|
| 1000 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
| correct output |
|---|
| 7987 |
| user output |
|---|
| 7987 |
Test 29
Group: 2
Verdict: RUNTIME ERROR
| input |
|---|
| 200000 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
| correct output |
|---|
| 3137875 |
| user output |
|---|
| (empty) |
Test 30
Group: 1, 2
Verdict: ACCEPTED
| input |
|---|
| 1000 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
| correct output |
|---|
| 4657693 |
| user output |
|---|
| 4657693 |
Test 31
Group: 2
Verdict: RUNTIME ERROR
| input |
|---|
| 200000 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
| correct output |
|---|
| 1652889357 |
| user output |
|---|
| (empty) |
