Task: | Distance Code |
Sender: | Luis Galan |
Submission time: | 2019-03-06 15:46:41 +0200 |
Language: | Java |
Status: | READY |
Result: | 0 |
group | verdict | score |
---|---|---|
#1 | RUNTIME ERROR | 0 |
#2 | RUNTIME ERROR | 0 |
#3 | RUNTIME ERROR | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | RUNTIME ERROR | 0.23 s | 1, 2, 3 | details |
#2 | WRONG ANSWER | 0.22 s | 1, 2, 3 | details |
#3 | WRONG ANSWER | 0.22 s | 1, 2, 3 | details |
#4 | WRONG ANSWER | 0.23 s | 1, 2, 3 | details |
#5 | RUNTIME ERROR | 0.24 s | 1, 2, 3 | details |
#6 | RUNTIME ERROR | 0.23 s | 1, 2, 3 | details |
#7 | WRONG ANSWER | 0.23 s | 1, 2, 3 | details |
#8 | WRONG ANSWER | 0.23 s | 1, 2, 3 | details |
#9 | WRONG ANSWER | 0.23 s | 1, 2, 3 | details |
#10 | WRONG ANSWER | 0.23 s | 1, 2, 3 | details |
#11 | WRONG ANSWER | 0.23 s | 1, 2, 3 | details |
#12 | WRONG ANSWER | 0.30 s | 2, 3 | details |
#13 | WRONG ANSWER | 0.28 s | 2, 3 | details |
#14 | WRONG ANSWER | 0.28 s | 2, 3 | details |
#15 | WRONG ANSWER | 0.28 s | 2, 3 | details |
#16 | TIME LIMIT EXCEEDED | -- | 3 | details |
#17 | WRONG ANSWER | 0.81 s | 3 | details |
#18 | WRONG ANSWER | 0.80 s | 3 | details |
#19 | WRONG ANSWER | 0.82 s | 3 | details |
#20 | WRONG ANSWER | 0.23 s | 1, 2, 3 | details |
Code
import java.util.Scanner; import java.util.ArrayList; public class distance { public static class Node { ArrayList<Node> children; Node parent; int id; public Node(int id) { children = new ArrayList<>(); this.id = id; } } public static void encode(Node root) { // remove nodes depth-first for (int i = 0; i < root.children.size(); i++) { encode(root.children.get(i)); } System.out.println(root.id + 1); } public static int decode(int[] distances, Node[] nodes, int pIndex) { // loop through nodes that belong to parent int i = pIndex - 1; while (i >= 0 && distances[i] == 1 + distances[pIndex]) { nodes[pIndex].children.add(nodes[i]); System.out.println((i + 1) + " " + (pIndex + 1)); i = decode(distances, nodes, i); } return i; } public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int t = Integer.parseInt(scanner.next()); int n = Integer.parseInt(scanner.next()); Node[] nodes = new Node[n]; for (int i = 0; i < nodes.length; i++) { nodes[i] = new Node(i); } if (t == 1) { // encode for (int i = 0; i < n - 1; i++) { int a = Integer.parseInt(scanner.next()); int b = Integer.parseInt(scanner.next()); nodes[a - 1].children.add(nodes[b - 1]); nodes[b - 1].parent = nodes[a - 1]; } Node root = nodes[0]; while (root.parent != null) { root = root.parent; } encode(root); } else { // decode // get distances int[] distances = new int[n + 1]; // add 0 as last element for (int i = 0; i < n; i++) { distances[i] = Integer.parseInt(scanner.next()); } // run decode with index = n - 1 decode(distances, nodes, n - 1); } scanner.close(); } }
Test details
Test 1
Group: 1, 2, 3
Verdict: RUNTIME ERROR
input |
---|
1 2 2 1 |
correct output |
---|
(empty) |
user output |
---|
(empty) |
Error:
Exception in thread "main" java.util.NoSuchElementException at java.base/java.util.Scanne...
Test 2
Group: 1, 2, 3
Verdict: WRONG ANSWER
input |
---|
1 3 3 1 2 1 |
correct output |
---|
(empty) |
user output |
---|
1 2 |
Test 3
Group: 1, 2, 3
Verdict: WRONG ANSWER
input |
---|
1 4 3 2 2 1 4 1 |
correct output |
---|
(empty) |
user output |
---|
1 4 |
Test 4
Group: 1, 2, 3
Verdict: WRONG ANSWER
input |
---|
1 4 2 3 3 4 1 3 |
correct output |
---|
(empty) |
user output |
---|
4 3 1 |
Test 5
Group: 1, 2, 3
Verdict: RUNTIME ERROR
input |
---|
1 5 3 5 4 1 1 3 ... |
correct output |
---|
(empty) |
user output |
---|
(empty) |
Error:
Exception in thread "main" java.util.NoSuchElementException at java.base/java.util.Scanne...
Test 6
Group: 1, 2, 3
Verdict: RUNTIME ERROR
input |
---|
1 5 3 2 3 4 5 1 ... |
correct output |
---|
(empty) |
user output |
---|
(empty) |
Error:
Exception in thread "main" java.util.NoSuchElementException at java.base/java.util.Scanne...
Test 7
Group: 1, 2, 3
Verdict: WRONG ANSWER
input |
---|
1 5 4 3 1 4 4 2 ... |
correct output |
---|
(empty) |
user output |
---|
3 2 4 1 |
Test 8
Group: 1, 2, 3
Verdict: WRONG ANSWER
input |
---|
1 10 9 3 8 9 2 9 ... |
correct output |
---|
(empty) |
user output |
---|
3 7 6 5 4 ... |
Test 9
Group: 1, 2, 3
Verdict: WRONG ANSWER
input |
---|
1 10 9 2 5 8 7 1 ... |
correct output |
---|
(empty) |
user output |
---|
2 8 6 1 7 ... |
Test 10
Group: 1, 2, 3
Verdict: WRONG ANSWER
input |
---|
1 10 10 4 9 1 4 7 ... |
correct output |
---|
(empty) |
user output |
---|
5 2 6 7 1 ... |
Test 11
Group: 1, 2, 3
Verdict: WRONG ANSWER
input |
---|
1 10 2 6 4 3 3 5 ... |
correct output |
---|
(empty) |
user output |
---|
8 6 2 1 |
Test 12
Group: 2, 3
Verdict: WRONG ANSWER
input |
---|
1 500 10 6 6 255 6 428 ... |
correct output |
---|
(empty) |
user output |
---|
255 428 108 238 437 ... Truncated |
Test 13
Group: 2, 3
Verdict: WRONG ANSWER
input |
---|
1 500 152 466 451 313 158 479 ... |
correct output |
---|
(empty) |
user output |
---|
243 47 1 |
Test 14
Group: 2, 3
Verdict: WRONG ANSWER
input |
---|
1 500 109 440 330 190 443 161 ... |
correct output |
---|
(empty) |
user output |
---|
20 217 1 |
Test 15
Group: 2, 3
Verdict: WRONG ANSWER
input |
---|
1 500 144 373 257 233 341 318 ... |
correct output |
---|
(empty) |
user output |
---|
270 70 218 488 405 ... |
Test 16
Group: 3
Verdict: TIME LIMIT EXCEEDED
input |
---|
1 100000 54983 75172 93807 75172 44082 75172 ... |
correct output |
---|
(empty) |
user output |
---|
(empty) |
Test 17
Group: 3
Verdict: WRONG ANSWER
input |
---|
1 100000 88863 19059 86423 76688 98536 95984 ... |
correct output |
---|
(empty) |
user output |
---|
85047 85005 1 |
Test 18
Group: 3
Verdict: WRONG ANSWER
input |
---|
1 100000 59979 6389 19097 24999 27846 82330 ... |
correct output |
---|
(empty) |
user output |
---|
60473 41037 1 |
Test 19
Group: 3
Verdict: WRONG ANSWER
input |
---|
1 100000 58761 66001 25102 51081 98625 67861 ... |
correct output |
---|
(empty) |
user output |
---|
30351 50013 1 |
Test 20
Group: 1, 2, 3
Verdict: WRONG ANSWER
input |
---|
1 6 2 1 3 2 4 2 ... |
correct output |
---|
(empty) |
user output |
---|
1 2 4 |