| Task: | Fragile network |
| Sender: | aalto25f_001 |
| Submission time: | 2025-10-08 17:49:09 +0300 |
| Language: | C++ (C++17) |
| Status: | READY |
| Result: | WRONG ANSWER |
| test | verdict | time | |
|---|---|---|---|
| #1 | WRONG ANSWER | 0.00 s | details |
| #2 | ACCEPTED | 0.00 s | details |
| #3 | WRONG ANSWER | 0.00 s | details |
| #4 | ACCEPTED | 0.00 s | details |
| #5 | WRONG ANSWER | 0.00 s | details |
| #6 | WRONG ANSWER | 0.04 s | details |
| #7 | ACCEPTED | 0.04 s | details |
| #8 | RUNTIME ERROR | 0.06 s | details |
| #9 | WRONG ANSWER | 0.04 s | details |
| #10 | WRONG ANSWER | 0.04 s | details |
| #11 | WRONG ANSWER | 0.00 s | details |
| #12 | ACCEPTED | 0.00 s | details |
| #13 | ACCEPTED | 0.00 s | details |
| #14 | WRONG ANSWER | 0.03 s | details |
| #15 | ACCEPTED | 0.00 s | details |
| #16 | ACCEPTED | 0.00 s | details |
| #17 | ACCEPTED | 0.00 s | details |
| #18 | WRONG ANSWER | 0.00 s | details |
| #19 | ACCEPTED | 0.00 s | details |
| #20 | WRONG ANSWER | 0.00 s | details |
| #21 | WRONG ANSWER | 0.00 s | details |
Code
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
typedef struct cell{
uint64_t val;
struct cell *next;
struct cell *prev;
} cell;
uint64_t *status;
uint64_t *values;
cell **calls;
uint64_t n, m, k;
cell *lc, *end;
void add(uint64_t id){
cell *c = (cell*) malloc(sizeof(cell));
c->val=id;
if(lc != NULL){
lc->prev = c;
} else {
end = c;
}
c->next = lc;
c->prev = NULL;
lc = c;
}
void explore(uint64_t id){
// printf("test : %ld\n", id);
if (status[id] == 1){
printf("No\n");
exit(EXIT_SUCCESS);
}
if (status[id] == 2){
return;
}
if (calls[id] == NULL){
k++;
status[id] = 2;
add(id);
return;
}
status[id] = 1;
cell *cur = calls[id];
while (cur != NULL){
explore(cur->val);
cur = cur->next;
}
status[id] = 2;
add(id);
}
int main() {
if (scanf("%ld", &n) == 0)
return EXIT_FAILURE;
m=n-1;
k=0;
calls = (cell**) calloc(n, sizeof(cell*));
uint64_t a, b;
cell *c;
for (uint64_t i = 0; i<m; i++){
if (scanf("%ld %ld", &a, &b) == 0)
return EXIT_FAILURE;
a--;
b--;
c = (cell*) malloc(sizeof(cell));
c->prev = NULL;
c->next = calls[a];
c->val = b;
calls[a] = c;
}
status = (uint64_t*) calloc(n, sizeof(uint64_t));
values = (uint64_t*) calloc(n, sizeof(uint64_t));
for (uint64_t i = 0; i<n; i++){
explore(i);
}
printf("%ld\n", (k+1)/2);
cell *prev_left = lc;
cell *left = lc;
cell *right = end;
while (right != left){
while (calls[left->val] != NULL && left != right)
left = left->next;
if (right == left){
printf("%ld %ld\n", prev_left->val+1, right->val+1);
exit(EXIT_SUCCESS);
}
while (calls[right->val] != NULL && left != right)
right = right->prev;
printf("%ld %ld\n", left->val+1, right->val+1);
prev_left = left;
left = left->next;
if (right == left){
printf("%ld %ld\n", prev_left->val+1, right->val+1);
exit(EXIT_SUCCESS);
}
right = right->prev;
}
return EXIT_SUCCESS;
}
Test details
Test 1
Verdict: WRONG ANSWER
| input |
|---|
| 10 1 5 1 7 1 8 1 3 ... |
| correct output |
|---|
| 5 5 2 7 9 8 6 3 10 ... |
| user output |
|---|
| 5 5 2 7 9 8 6 3 10 |
Test 2
Verdict: ACCEPTED
| input |
|---|
| 10 4 5 3 4 2 3 9 10 ... |
| correct output |
|---|
| 1 10 1 |
| user output |
|---|
| 1 1 10 |
Test 3
Verdict: WRONG ANSWER
| input |
|---|
| 10 1 8 1 3 3 5 5 7 ... |
| correct output |
|---|
| 3 7 10 8 2 1 9 |
| user output |
|---|
| 3 8 2 7 10 7 9 |
Test 4
Verdict: ACCEPTED
| input |
|---|
| 10 1 5 3 7 2 10 3 8 ... |
| correct output |
|---|
| 3 10 8 6 4 5 9 |
| user output |
|---|
| 3 5 4 6 8 10 9 10 7 |
Test 5
Verdict: WRONG ANSWER
| input |
|---|
| 10 4 8 3 4 4 6 2 3 ... |
| correct output |
|---|
| 3 8 7 10 9 1 6 |
| user output |
|---|
| 3 10 9 8 7 |
Test 6
Verdict: WRONG ANSWER
| input |
|---|
| 100000 1 56967 1 56618 1 42321 1 82550 ... |
| correct output |
|---|
| 50000 56967 16911 56618 39942 42321 99902 82550 2538 ... |
| user output |
|---|
| 50000 56967 16911 56618 39942 42321 99902 82550 2538 ... |
Test 7
Verdict: ACCEPTED
| input |
|---|
| 100000 92297 92298 23511 23512 68057 68058 65434 65435 ... |
| correct output |
|---|
| 1 100000 1 |
| user output |
|---|
| 1 1 100000 |
Test 8
Verdict: RUNTIME ERROR
| input |
|---|
| 100000 17747 97512 10397 12053 679 6975 4013 14565 ... |
| correct output |
|---|
| 25057 92881 76094 20353 87429 16069 96487 71186 52809 ... |
| user output |
|---|
| 25057 92881 30042 20353 78413 76094 77655 16069 86897 ... |
Test 9
Verdict: WRONG ANSWER
| input |
|---|
| 100000 72941 72942 11232 11233 73464 73465 30042 30043 ... |
| correct output |
|---|
| 489 16423 85168 20707 94190 36505 54940 96411 44067 ... |
| user output |
|---|
| 488 21977 50311 4831 99 5346 9350 16423 57383 ... |
Test 10
Verdict: WRONG ANSWER
| input |
|---|
| 100000 31451 31452 7473 7474 24056 24057 85181 85182 ... |
| correct output |
|---|
| 51 25638 2983 87594 87371 92001 50610 46744 100000 ... |
| user output |
|---|
| 50 63319 140 64101 64192 25638 51874 42311 53106 ... |
Test 11
Verdict: WRONG ANSWER
| input |
|---|
| 10 1 2 1 3 3 4 3 5 ... |
| correct output |
|---|
| 2 2 6 4 10 |
| user output |
|---|
| 2 2 10 4 6 |
Test 12
Verdict: ACCEPTED
| input |
|---|
| 7 1 2 2 3 2 4 1 5 ... |
| correct output |
|---|
| 2 4 7 3 6 |
| user output |
|---|
| 2 3 7 4 6 |
Test 13
Verdict: ACCEPTED
| input |
|---|
| 6 1 2 1 3 1 4 4 5 ... |
| correct output |
|---|
| 2 3 6 2 5 |
| user output |
|---|
| 2 2 6 3 5 |
Test 14
Verdict: WRONG ANSWER
| input |
|---|
| 65538 1 2 1 3 1 4 3 5 ... |
| correct output |
|---|
| 16385 34 36 40 42 35 41 48 50 ... |
| user output |
|---|
| 16385 2 4 33 65538 34 65537 35 65536 ... |
Test 15
Verdict: ACCEPTED
| input |
|---|
| 11 1 2 1 3 2 4 2 5 ... |
| correct output |
|---|
| 2 9 11 8 10 |
| user output |
|---|
| 2 8 11 9 10 9 6 |
Test 16
Verdict: ACCEPTED
| input |
|---|
| 7 1 2 1 3 2 4 2 5 ... |
| correct output |
|---|
| 2 5 7 4 6 |
| user output |
|---|
| 2 4 7 5 6 |
Test 17
Verdict: ACCEPTED
| input |
|---|
| 7 1 2 1 3 2 4 2 5 ... |
| correct output |
|---|
| 2 5 7 4 6 |
| user output |
|---|
| 2 4 7 5 6 |
Test 18
Verdict: WRONG ANSWER
| input |
|---|
| 10 8 4 3 4 4 6 2 3 ... |
| correct output |
|---|
| 3 8 7 10 9 1 6 |
| user output |
|---|
| 2 10 9 6 7 6 7 |
Test 19
Verdict: ACCEPTED
| input |
|---|
| 7 1 2 1 5 2 3 2 6 ... |
| correct output |
|---|
| 2 6 7 3 4 |
| user output |
|---|
| 2 3 7 6 4 |
Test 20
Verdict: WRONG ANSWER
| input |
|---|
| 8 1 2 1 3 2 4 2 5 ... |
| correct output |
|---|
| 3 4 7 6 8 1 5 |
| user output |
|---|
| 3 4 8 5 7 |
Test 21
Verdict: WRONG ANSWER
| input |
|---|
| 10 2 1 3 1 4 2 5 4 ... |
| correct output |
|---|
| 3 9 8 6 10 3 7 |
| user output |
|---|
| 1 10 1 |
