Submission details
Task:Shortest Routes I
Sender:aalto26fh_050
Submission time:2026-10-01 12:31:36 +0300
Language:Java
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.09 sdetails
#2ACCEPTED0.09 sdetails
#3ACCEPTED0.08 sdetails
#4ACCEPTED0.09 sdetails
#5ACCEPTED0.09 sdetails
#61.06 sdetails
#71.09 sdetails
#81.07 sdetails
#91.09 sdetails
#101.09 sdetails
#11ACCEPTED0.86 sdetails
#120.85 sdetails
#13ACCEPTED0.09 sdetails
#14ACCEPTED0.87 sdetails
#15ACCEPTED0.87 sdetails
#16ACCEPTED0.70 sdetails
#17ACCEPTED0.70 sdetails
#18ACCEPTED1.04 sdetails

Code

import java.io.IOException;
import java.io.StreamTokenizer;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Node {
    public int id, price;

    public Node(int id, int price) {
        this.id = id;
        this.price = price;
    }

    @Override
    public String toString() {
        return String.format("Node(%d, %d)", id, price);
    }
}

class Edge {
    public int from, to, length;

    public Edge(int from, int to, int length) {
        this.from = from;
        this.to = to;
        this.length = length;
    }
}

public class ShortestRoutesI {

    public static void main(String[] args) throws IOException {

        StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        in.nextToken();
        int n = (int) in.nval;
        in.nextToken();
        int m = (int) in.nval;

        ArrayList<ArrayList<Edge>> adj = new ArrayList<>(n);
        for (int i = 0; i < n; i++)
            adj.add(new ArrayList<>());

        for (int i = 0; i < m; i++) {
            in.nextToken();
            int a = (int) in.nval;
            in.nextToken();
            int b = (int) in.nval;
            in.nextToken();
            int c = (int) in.nval;
            adj.get(a - 1).add(new Edge(a, b, c));
        }

        PriorityQueue<Node> pq = new PriorityQueue<>(n, Comparator.comparingInt((Node node) -> node.price));
        pq.offer(new Node(1, 0));

        int[] dist = new int[n];
        boolean[] visited = new boolean[n];
        for (int i = 0; i < dist.length; i++)
            dist[i] = Integer.MAX_VALUE;
        dist[0] = 0;

        while (!pq.isEmpty()) {
            Node current = pq.poll();

            if (visited[current.id - 1])
                continue;
            visited[current.id - 1] = true;

            for (Edge edge : adj.get(current.id - 1)) {
                int newDist = current.price + edge.length;
                if (newDist < dist[edge.to - 1]) {
                    pq.offer(new Node(edge.to, newDist));
                    dist[edge.to - 1] = newDist;
                }
            }
        }

        for (int d : dist)
            System.out.print(d + " ");
    }

}

Test details

Test 1

Verdict: ACCEPTED

input
10 20
8 5 1
9 10 2
7 9 8
9 8 8
...

correct output
0 9 11 20 13 14 19 29 27 29 

user output
0 9 11 20 13 14 19 29 27 29 

Test 2

Verdict: ACCEPTED

input
10 20
5 6 4
5 1 7
7 4 4
7 8 1
...

correct output
0 7 9 17 15 17 21 22 25 30 

user output
0 7 9 17 15 17 21 22 25 30 

Test 3

Verdict: ACCEPTED

input
10 20
1 4 1
4 2 1
9 10 1
1 2 4
...

correct output
0 2 11 1 2 7 16 18 12 13 

user output
0 2 11 1 2 7 16 18 12 13 

Test 4

Verdict: ACCEPTED

input
10 20
6 3 5
7 5 8
5 1 8
8 9 5
...

correct output
0 5 9 18 22 10 14 23 27 36 

user output
0 5 9 18 22 10 14 23 27 36 

Test 5

Verdict: ACCEPTED

input
10 20
8 9 3
2 3 8
10 5 3
2 5 3
...

correct output
0 8 16 18 11 17 24 23 16 26 

user output
0 8 16 18 11 17 24 23 16 26 

Test 6

Verdict:

input
100000 200000
18000 18001 426710313
73018 73012 558438094
87726 87671 355171790
53170 53171 869493690
...

correct output
0 479659405 1165315262 1854343...

user output
0 479659405 1165315262 1854343...

Feedback: Incorrect character on line 1 col 35: expected "2003994862", got "-530592719"

Test 7

Verdict:

input
100000 200000
26504 26450 258578924
49543 49544 28958186
75174 75175 89459846
39175 39228 119699475
...

correct output
0 655556128 1413395076 1814086...

user output
0 655556128 749227710 -1052132...

Feedback: Incorrect character on line 1 col 13: expected "1413395076", got "749227710"

Test 8

Verdict:

input
100000 200000
39477 39413 773046299
69758 69759 558754983
23279 23280 142570619
61416 61479 874921013
...

correct output
0 269736525 626115013 70199222...

user output
0 269736525 583227957 70199222...

Feedback: Incorrect character on line 1 col 13: expected "626115013", got "583227957"

Test 9

Verdict:

input
100000 200000
76662 76636 844365635
73339 73342 755006676
89878 89879 396562588
18801 18781 954807004
...

correct output
0 598585836 1267139909 1803859...

user output
-1719864565 598585836 12671399...

Feedback: Incorrect character on line 1 col 1: expected "0", got "-1719864565"

Test 10

Verdict:

input
100000 200000
11724 11725 818399968
33244 33197 722525474
65530 65531 483965413
62405 62454 199581867
...

correct output
0 387990617 441010945 92441292...

user output
0 387990617 441010945 -7640559...

Feedback: Incorrect character on line 1 col 23: expected "924412922", got "-764055947"

Test 11

Verdict: ACCEPTED

input
100000 200000
1 2 1
1 3 1
1 4 1
1 5 1
...

correct output
0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

user output
0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

Test 12

Verdict:

input
100000 99999
1 2 1000000000
2 3 1000000000
3 4 1000000000
4 5 1000000000
...

correct output
0 1000000000 2000000000 300000...

user output
0 1000000000 2000000000 -12949...

Feedback: Incorrect character on line 1 col 25: expected "3000000000", got "-1294967296"

Test 13

Verdict: ACCEPTED

input
1 1
1 1 1

correct output
0 

user output
0 

Test 14

Verdict: ACCEPTED

input
99999 149997
1 2 1
2 3 1
3 4 1
4 5 1
...

correct output
0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 ...

user output
0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 ...

Test 15

Verdict: ACCEPTED

input
99997 149994
1 3 3
3 5 3
5 7 3
7 9 3
...

correct output
0 1 2 3 4 5 6 7 8 9 10 11 12 1...

user output
0 1 2 3 4 5 6 7 8 9 10 11 12 1...

Test 16

Verdict: ACCEPTED

input
60003 120000
1 2 30010
1 3 30010
1 4 30010
1 5 30010
...

correct output
0 30010 30010 30010 30010 3001...

user output
0 30010 30010 30010 30010 3001...

Test 17

Verdict: ACCEPTED

input
60003 120000
1 2 30010
1 3 30010
1 4 30010
1 5 30010
...

correct output
0 30010 30010 30010 30010 3001...

user output
0 30010 30010 30010 30010 3001...

Test 18

Verdict: ACCEPTED

input
100000 149997
1 50000 99997
1 49999 99995
1 49998 99993
1 49997 99991
...

correct output
0 1 3 5 7 9 11 13 15 17 19 21 ...

user output
0 1 3 5 7 9 11 13 15 17 19 21 ...